git.iko.soy/typeable/pandoc
on master help sign in
LaTeX template: define commands for zero width non-joiner character
d92622bAlbert Krewinkel
data/templates/default.latex+19
@@ -156,6 +156,25 @@ $if(CJKmainfont)$
156 \fi
156 \fi
157$endif$
157$endif$
158\fi
158\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$
159$if(beamer)$
178$if(beamer)$
160$if(theme)$
179$if(theme)$
161\usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$}
180\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
173 defField "has-chapters" (stHasChapters st) $
173 defField "has-chapters" (stHasChapters st) $
174 defField "has-frontmatter" (documentClass `elem` frontmatterClasses) $
174 defField "has-frontmatter" (documentClass `elem` frontmatterClasses) $
175 defField "listings" (writerListings options || stLHS st) $
175 defField "listings" (writerListings options || stLHS st) $
176+ defField "zero-width-non-joiner" (stZwnj st) $
176 defField "beamer" beamer $
177 defField "beamer" beamer $
177 (if stHighlighting st
178 (if stHighlighting st
178 then case writerHighlightStyle options of
179 then case writerHighlightStyle options of
@@ -1048,5 +1049,3 @@ extractInline _ _ = []
1048-- Look up a key in an attribute and give a list of its values
1049-- Look up a key in an attribute and give a list of its values
1049lookKey :: Text -> Attr -> [Text]
1050lookKey :: Text -> Attr -> [Text]
1050lookKey key (_,_,kvs) = maybe [] T.words $ lookup key kvs
1051lookKey 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 =
40 , stCsquotes :: Bool -- ^ true if document uses csquotes
40 , stCsquotes :: Bool -- ^ true if document uses csquotes
41 , stHighlighting :: Bool -- ^ true if document has highlighted code
41 , stHighlighting :: Bool -- ^ true if document has highlighted code
42 , stIncremental :: Bool -- ^ true if beamer lists should be
42 , stIncremental :: Bool -- ^ true if beamer lists should be
43− -- displayed bit by bit
43+ , stZwnj :: Bool -- ^ true if document has a ZWNJ character
44 , stInternalLinks :: [Text] -- ^ list of internal link targets
44 , stInternalLinks :: [Text] -- ^ list of internal link targets
45 , stBeamer :: Bool -- ^ produce beamer
45 , stBeamer :: Bool -- ^ produce beamer
46 , stEmptyLine :: Bool -- ^ true if no content on line
46 , stEmptyLine :: Bool -- ^ true if no content on line
@@ -74,6 +74,7 @@ startingState options =
74 , stCsquotes = False
74 , stCsquotes = False
75 , stHighlighting = False
75 , stHighlighting = False
76 , stIncremental = writerIncremental options
76 , stIncremental = writerIncremental options
77+ , stZwnj = False
77 , stInternalLinks = []
78 , stInternalLinks = []
78 , stBeamer = False
79 , stBeamer = False
79 , stEmptyLine = True
80 , stEmptyLine = True
src/Text/Pandoc/Writers/LaTeX/Util.hs+4−3
@@ -22,6 +22,7 @@ module Text.Pandoc.Writers.LaTeX.Util (
22where
22where
23
23
24import Control.Applicative ((<|>))
24import Control.Applicative ((<|>))
25+import Control.Monad (when)
25import Text.Pandoc.Class (PandocMonad, toLang)
26import Text.Pandoc.Class (PandocMonad, toLang)
26import Text.Pandoc.Options (WriterOptions(..), isEnabled)
27import Text.Pandoc.Options (WriterOptions(..), isEnabled)
27import Text.Pandoc.Writers.LaTeX.Types (LW, WriterState(..))
28import Text.Pandoc.Writers.LaTeX.Types (LW, WriterState(..))
@@ -30,7 +31,7 @@ import Text.Pandoc.Highlighting (toListingsLanguage)
30import Text.DocLayout
31import Text.DocLayout
31import Text.Pandoc.Definition
32import Text.Pandoc.Definition
32import Text.Pandoc.ImageSize (showFl)
33import Text.Pandoc.ImageSize (showFl)
33−import Control.Monad.State.Strict (gets)
34+import Control.Monad.State.Strict (gets, modify)
34import Data.Text (Text)
35import Data.Text (Text)
35import qualified Data.Text as T
36import qualified Data.Text as T
36import Text.Pandoc.Extensions (Extension(Ext_smart))
37import Text.Pandoc.Extensions (Extension(Ext_smart))
@@ -49,6 +50,8 @@ data StringContext = TextString
49stringToLaTeX :: PandocMonad m => StringContext -> Text -> LW m Text
50stringToLaTeX :: PandocMonad m => StringContext -> Text -> LW m Text
50stringToLaTeX context zs = do
51stringToLaTeX context zs = do
51 opts <- gets stOptions
52 opts <- gets stOptions
53+ when ('\x200c' `elemText` zs) $
54+ modify (\s -> s { stZwnj = True })
52 return $ T.pack $
55 return $ T.pack $
53 foldr (go opts context) mempty $ T.unpack $
56 foldr (go opts context) mempty $ T.unpack $
54 if writerPreferAscii opts
57 if writerPreferAscii opts
@@ -270,5 +273,3 @@ mbBraced :: Text -> Text
270mbBraced x = if not (T.all isAlphaNum x)
273mbBraced x = if not (T.all isAlphaNum x)
271 then "{" <> x <> "}"
274 then "{" <> x <> "}"
272 else x
275 else x
273−
274−