Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write non-breaking space as "~" in LaTeXWriter #2300

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
mortenpi marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

* Non-breaking spaces are now properly converted as "~" in the `LaTeXWriter`.
mortenpi marked this conversation as resolved.
Show resolved Hide resolved


## Version [v1.1.1] - 2023-10-12

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Documenter"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "1.1.1"
version = "1.1.2-dev"
mortenpi marked this conversation as resolved.
Show resolved Hide resolved

[deps]
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
Expand Down
1 change: 1 addition & 0 deletions src/latex/LaTeXWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ latex(io::Context, node::Node, ::MarkdownAST.LineBreak) = _println(io, "\\\\")

const _latexescape_chars = Dict{Char, AbstractString}(
'~' => "{\\textasciitilde}",
'\u00A0' => "~", # nonbreaking space
'^' => "{\\textasciicircum}",
'\\' => "{\\textbackslash}",
'\'' => "{\\textquotesingle}",
Expand Down
36 changes: 36 additions & 0 deletions test/latexwriter.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module LaTeXWriterTests

using Test
import Documenter
import Documenter.LaTeXWriter

@testset "file ordering" begin
Expand Down Expand Up @@ -32,4 +33,39 @@ import Documenter.LaTeXWriter
]
end


function _dummy_lctx()
doc = Documenter.Document()
buffer = IOBuffer()
return LaTeXWriter.Context(buffer, doc)
end

function _latexesc(str)
lctx = _dummy_lctx()
LaTeXWriter.latexesc(lctx, str)
return String(take!(lctx.io))
end

function _md_to_latex(mdstr)
lctx = _dummy_lctx()
ast = Documenter.mdparse(mdstr; mode=:single)[1]
LaTeXWriter.latex(lctx, ast.children) # should use latexesc internally
return String(take!(lctx.io))
end


@testset "latex escapes" begin

md = "~ Ref.\u00A0[1], O'Reilly, \"Book #1\""
tex = "{\\textasciitilde} Ref.~[1], O{\\textquotesingle}Reilly, {\\textquotedbl}Book \\#1{\\textquotedbl}"
@test _latexesc(md) == tex
@test _md_to_latex(md) == tex

md = "[DocumenterCitations.jl](https://github.com/JuliaDocs/DocumenterCitations.jl#readme)"
tex = "\\href{https://github.com/JuliaDocs/DocumenterCitations.jl\\#readme}{DocumenterCitations.jl}"
@test _md_to_latex(md) == tex

end


end
Loading