git.iko.soy/typeable/pandoc
on master help sign in
LaTeX template: define commands for zero width non-joiner character

Closes: #6639 The zero-width non-joiner character is used to avoid ligatures (e.g. in German).

commitd92622ba3cae5ced69a256472d367a53fc5878a1 authorAlbert Krewinkel <albert@zeitkraut.de> dateSun 16 May 2021, 21:33 (5 years ago) parent5a6399d
4 files changed+26−6
data/templates/default.latex+19 src/Text/Pandoc/Writers/LaTeX.hs+1−2 src/Text/Pandoc/Writers/LaTeX/Types.hs+2−1 src/Text/Pandoc/Writers/LaTeX/Util.hs+4−3
data/templates/default.latex+19
@@ -156,6 +156,25 @@ $if(CJKmainfont)$
156156 \fi
157157$endif$
158158\fi
159+$if(zero-width-non-joiner)$
160+%% Support for zero-width non-joiner characters.
161+\makeatletter
162+\def\zerowidthnonjoiner{%
163+ % Prevent ligatures and adjust kerning, but still support hyphenating.
164+ \texorpdfstring{%
165+ \textormath{\nobreak\discretionary{-}{}{\kern.03em}%
166+ \ifvmode\else\nobreak\hskip\z@skip\fi}{}%
167+ }{}%
168+}
169+\makeatother
170+\ifPDFTeX
171+ \DeclareUnicodeCharacter{200C}{\zerowidthnonjoiner}
172+\else
173+ \catcode`^^^^200c=\active
174+ \protected\def ^^^^200c{\zerowidthnonjoiner}
175+\fi
176+%% End of ZWNJ support
177+$endif$
159178$if(beamer)$
160179$if(theme)$
161180\usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$}
src/Text/Pandoc/Writers/LaTeX.hs+1−2
@@ -173,6 +173,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
173173 defField "has-chapters" (stHasChapters st) $
174174 defField "has-frontmatter" (documentClass `elem` frontmatterClasses) $
175175 defField "listings" (writerListings options || stLHS st) $
176+ defField "zero-width-non-joiner" (stZwnj st) $
176177 defField "beamer" beamer $
177178 (if stHighlighting st
178179 then case writerHighlightStyle options of
@@ -1048,5 +1049,3 @@ extractInline _ _ = []
10481049-- Look up a key in an attribute and give a list of its values
10491050lookKey :: Text -> Attr -> [Text]
10501051lookKey key (_,_,kvs) = maybe [] T.words $ lookup key kvs
1051−
1052−
src/Text/Pandoc/Writers/LaTeX/Types.hs+2−1
@@ -40,7 +40,7 @@ data WriterState =
4040 , stCsquotes :: Bool -- ^ true if document uses csquotes
4141 , stHighlighting :: Bool -- ^ true if document has highlighted code
4242 , stIncremental :: Bool -- ^ true if beamer lists should be
43− -- displayed bit by bit
43+ , stZwnj :: Bool -- ^ true if document has a ZWNJ character
4444 , stInternalLinks :: [Text] -- ^ list of internal link targets
4545 , stBeamer :: Bool -- ^ produce beamer
4646 , stEmptyLine :: Bool -- ^ true if no content on line
@@ -74,6 +74,7 @@ startingState options =
7474 , stCsquotes = False
7575 , stHighlighting = False
7676 , stIncremental = writerIncremental options
77+ , stZwnj = False
7778 , stInternalLinks = []
7879 , stBeamer = False
7980 , stEmptyLine = True
src/Text/Pandoc/Writers/LaTeX/Util.hs+4−3
@@ -22,6 +22,7 @@ module Text.Pandoc.Writers.LaTeX.Util (
2222where
2323
2424import Control.Applicative ((<|>))
25+import Control.Monad (when)
2526import Text.Pandoc.Class (PandocMonad, toLang)
2627import Text.Pandoc.Options (WriterOptions(..), isEnabled)
2728import Text.Pandoc.Writers.LaTeX.Types (LW, WriterState(..))
@@ -30,7 +31,7 @@ import Text.Pandoc.Highlighting (toListingsLanguage)
3031import Text.DocLayout
3132import Text.Pandoc.Definition
3233import Text.Pandoc.ImageSize (showFl)
33−import Control.Monad.State.Strict (gets)
34+import Control.Monad.State.Strict (gets, modify)
3435import Data.Text (Text)
3536import qualified Data.Text as T
3637import Text.Pandoc.Extensions (Extension(Ext_smart))
@@ -49,6 +50,8 @@ data StringContext = TextString
4950stringToLaTeX :: PandocMonad m => StringContext -> Text -> LW m Text
5051stringToLaTeX context zs = do
5152 opts <- gets stOptions
53+ when ('\x200c' `elemText` zs) $
54+ modify (\s -> s { stZwnj = True })
5255 return $ T.pack $
5356 foldr (go opts context) mempty $ T.unpack $
5457 if writerPreferAscii opts
@@ -270,5 +273,3 @@ mbBraced :: Text -> Text
270273mbBraced x = if not (T.all isAlphaNum x)
271274 then "{" <> x <> "}"
272275 else x
273−
274−