git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer:
1be1f77fiddlosopher
src/Text/Pandoc/Writers/LaTeX.hs+14−12
@@ -34,7 +34,6 @@ import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35import Text.Printf ( printf )
35import Text.Printf ( printf )
36import Data.List ( (\\), isInfixOf )
36import Data.List ( (\\), isInfixOf )
37−import Data.Char ( isAlphaNum )
38import qualified Data.Set as S
37import qualified Data.Set as S
39import Control.Monad.State
38import Control.Monad.State
40
39
@@ -187,7 +186,7 @@ tableRowToLaTeX cols =
187listItemToLaTeX lst = blockListToLaTeX lst >>= (return . ("\\item "++))
186listItemToLaTeX lst = blockListToLaTeX lst >>= (return . ("\\item "++))
188
187
189defListItemToLaTeX (term, def) = do
188defListItemToLaTeX (term, def) = do
190− term' <- inlineListToLaTeX term
189+ term' <- inlineListToLaTeX $ deVerb term
191 def' <- blockListToLaTeX def
190 def' <- blockListToLaTeX def
192 return $ "\\item[" ++ term' ++ "] " ++ def'
191 return $ "\\item[" ++ term' ++ "] " ++ def'
193
192
@@ -206,28 +205,31 @@ isQuoted _ = False
206inlineToLaTeX :: Inline -- ^ Inline to convert
205inlineToLaTeX :: Inline -- ^ Inline to convert
207 -> State WriterState String
206 -> State WriterState String
208inlineToLaTeX (Emph lst) = do
207inlineToLaTeX (Emph lst) = do
209− contents <- inlineListToLaTeX lst
208+ contents <- inlineListToLaTeX $ deVerb lst
210 return $ "\\emph{" ++ contents ++ "}"
209 return $ "\\emph{" ++ contents ++ "}"
211inlineToLaTeX (Strong lst) = do
210inlineToLaTeX (Strong lst) = do
212− contents <- inlineListToLaTeX lst
211+ contents <- inlineListToLaTeX $ deVerb lst
213 return $ "\\textbf{" ++ contents ++ "}"
212 return $ "\\textbf{" ++ contents ++ "}"
214inlineToLaTeX (Strikeout lst) = do
213inlineToLaTeX (Strikeout lst) = do
215− contents <- inlineListToLaTeX lst
214+ contents <- inlineListToLaTeX $ deVerb lst
216 addToHeader "\\usepackage[normalem]{ulem}"
215 addToHeader "\\usepackage[normalem]{ulem}"
217 return $ "\\sout{" ++ contents ++ "}"
216 return $ "\\sout{" ++ contents ++ "}"
218inlineToLaTeX (Superscript lst) = do
217inlineToLaTeX (Superscript lst) = do
219− contents <- inlineListToLaTeX lst
218+ contents <- inlineListToLaTeX $ deVerb lst
220 return $ "\\textsuperscript{" ++ contents ++ "}"
219 return $ "\\textsuperscript{" ++ contents ++ "}"
221inlineToLaTeX (Subscript lst) = do
220inlineToLaTeX (Subscript lst) = do
222− contents <- inlineListToLaTeX lst
221+ contents <- inlineListToLaTeX $ deVerb lst
223 -- oddly, latex includes \textsuperscript but not \textsubscript
222 -- oddly, latex includes \textsuperscript but not \textsubscript
224 -- so we have to define it:
223 -- so we have to define it:
225 addToHeader "\\newcommand{\\textsubscript}[1]{\\ensuremath{_{\\scriptsize\\textrm{#1}}}}"
224 addToHeader "\\newcommand{\\textsubscript}[1]{\\ensuremath{_{\\scriptsize\\textrm{#1}}}}"
226 return $ "\\textsubscript{" ++ contents ++ "}"
225 return $ "\\textsubscript{" ++ contents ++ "}"
227−inlineToLaTeX (Code str) = return $ "\\Q{" ++ stuffing ++ "}"
226+inlineToLaTeX (Code str) = do
228− where stuffing = concatMap (\c -> if isAlphaNum c
227+ st <- get
229− then [c]
228+ if stInNote st
229+ then do addToHeader "\\usepackage{fancyvrb}"
230− else ['\\',c]) str
230+ else return ()
231+ let chr = ((enumFromTo '!' '~') \\ str) !! 0
232+ return $ "\\verb" ++ [chr] ++ str ++ [chr]
231inlineToLaTeX (Quoted SingleQuote lst) = do
233inlineToLaTeX (Quoted SingleQuote lst) = do
232 contents <- inlineListToLaTeX lst
234 contents <- inlineListToLaTeX lst
233 let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
235 let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
@@ -248,7 +250,7 @@ inlineToLaTeX (HtmlInline str) = return ""
248inlineToLaTeX (LineBreak) = return "\\\\\n"
250inlineToLaTeX (LineBreak) = return "\\\\\n"
249inlineToLaTeX Space = return " "
251inlineToLaTeX Space = return " "
250inlineToLaTeX (Link text (src, tit)) = do
252inlineToLaTeX (Link text (src, tit)) = do
251− contents <- inlineListToLaTeX text
253+ contents <- inlineListToLaTeX $ deVerb text
252 addToHeader "\\usepackage[breaklinks=true]{hyperref}"
254 addToHeader "\\usepackage[breaklinks=true]{hyperref}"
253 return $ "\\href{" ++ src ++ "}{" ++ contents ++ "}"
255 return $ "\\href{" ++ src ++ "}{" ++ contents ++ "}"
254inlineToLaTeX (Image alternate (source, tit)) = do
256inlineToLaTeX (Image alternate (source, tit)) = do