Skip to content

Commit

Permalink
Write non-breaking space as "~" in LaTeXWriter (#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz authored Oct 23, 2023
1 parent 46bf067 commit 6052e5f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
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).

## Version [v1.1.2] - 2023-10-23

### Fixed

* Non-breaking spaces are now properly converted as "~" in the `LaTeXWriter`. ([#2300])


## 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"

[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
11 changes: 11 additions & 0 deletions test/examples/references/latex_simple.tex
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,15 @@ \section{\texttt{LineBreak} node}
\section{Issue 2300}
\label{5494601647308340695}{}
You~Shall~Not~Break!~You~Shall~Not~Break!~You~Shall~Not~Break!
\end{document}
4 changes: 4 additions & 0 deletions test/examples/src.latex_simple/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ LaTeXEquation2(raw"""
This sentence\
should be over **multiple\
lines**.

## Issue 2300

You Shall Not Break! You Shall Not Break! You Shall Not Break!
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

0 comments on commit 6052e5f

Please sign in to comment.