aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-07-28 01:10:04 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-07-28 01:10:04 +0000
commitb29f221cba949934dda402f96b1606cda8ed73a6 (patch)
tree580d523e7c5980164d25527c27894865845c10f7 /src
parent4283ce3662cbb4b9d3165aef40455203ae106c47 (diff)
downloadpandoc-b29f221cba949934dda402f96b1606cda8ed73a6.tar.gz
Changed LaTeX writer to use the examplep package instead
of fancyvrb. examplep allows verbatim text in places where fancyvrb does not, e.g. definition list terms, and provides for line-breaking of verbatim text. + examplep code put in LaTeX header instead of being dynamically included, since it is frequently used, and people may want to customize the options. + documented dependency on examplep + added texlive-latex-extra as a "Suggested" package in debian/control + use examplep's \Q{} is now used instead of \verb: note that \Q requires backslash- escaping symbols in its scope. + modified README so that the verbatim sections will look good at shorter line lengths. git-svn-id: https://pandoc.googlecode.com/svn/trunk@807 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs32
-rw-r--r--src/headers/LaTeXHeader1
-rw-r--r--src/wrappers/markdown2pdf.in6
3 files changed, 19 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index cc2da8338..c9c923dae 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -34,6 +34,7 @@ import Text.Pandoc.Definition
import Text.Pandoc.Shared
import Text.Printf ( printf )
import Data.List ( (\\), isInfixOf )
+import Data.Char ( isAlphaNum )
import qualified Data.Set as S
import Control.Monad.State
@@ -81,15 +82,12 @@ latexHeader options (Meta title authors date) = do
then ""
else "\\date{" ++ stringToLaTeX date ++ "}\n"
let maketitle = if null title then "" else "\\maketitle\n"
- let verbatim = if "\\usepackage{fancyvrb}" `isInfixOf` extras
- then "\\VerbatimFootnotes % allows verbatim text in footnotes\n"
- else ""
let secnumline = if (writerNumberSections options)
then ""
else "\\setcounter{secnumdepth}{0}\n"
let baseHeader = writerHeader options
let header = baseHeader ++ extras
- return $ header ++ secnumline ++ verbatim ++ titletext ++ authorstext ++
+ return $ header ++ secnumline ++ titletext ++ authorstext ++
datetext ++ "\\begin{document}\n" ++ maketitle ++ "\n"
-- escape things as needed for LaTeX
@@ -106,11 +104,11 @@ stringToLaTeX = escapeStringUsing latexEscapes
]
-- | Remove all code elements from list of inline elements
--- (because it's illegal to have a \\verb inside a command argument)
+-- (because it's illegal to have verbatim inside some command arguments)
deVerb :: [Inline] -> [Inline]
deVerb [] = []
deVerb ((Code str):rest) =
- (Str $ stringToLaTeX str):(deVerb rest)
+ (TeX $ "\\texttt{" ++ stringToLaTeX str ++ "}"):(deVerb rest)
deVerb (other:rest) = other:(deVerb rest)
-- | Convert Pandoc block element to LaTeX.
@@ -155,7 +153,7 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
AlignCenter -> "\\centering"
AlignDefault -> "\\raggedright") ++
"\\hspace{0pt}}p{" ++ width ++
- "\\textwidth}")
+ "\\columnwidth}")
colWidths aligns
let tableBody = "\\begin{tabular}{" ++ colDescriptors ++ "}\n" ++
headers ++ "\\hline\n" ++ concat rows' ++ "\\end{tabular}\n"
@@ -177,7 +175,7 @@ tableRowToLaTeX cols =
listItemToLaTeX lst = blockListToLaTeX lst >>= (return . ("\\item "++))
defListItemToLaTeX (term, def) = do
- term' <- inlineListToLaTeX (deVerb term)
+ term' <- inlineListToLaTeX term
def' <- blockListToLaTeX def
return $ "\\item[" ++ term' ++ "] " ++ def'
@@ -196,27 +194,28 @@ isQuoted _ = False
inlineToLaTeX :: Inline -- ^ Inline to convert
-> State WriterState String
inlineToLaTeX (Emph lst) = do
- contents <- inlineListToLaTeX (deVerb lst)
+ contents <- inlineListToLaTeX lst
return $ "\\emph{" ++ contents ++ "}"
inlineToLaTeX (Strong lst) = do
- contents <- inlineListToLaTeX (deVerb lst)
+ contents <- inlineListToLaTeX lst
return $ "\\textbf{" ++ contents ++ "}"
inlineToLaTeX (Strikeout lst) = do
- contents <- inlineListToLaTeX (deVerb lst)
+ contents <- inlineListToLaTeX lst
addToHeader "\\usepackage[normalem]{ulem}"
return $ "\\sout{" ++ contents ++ "}"
inlineToLaTeX (Superscript lst) = do
- contents <- inlineListToLaTeX (deVerb lst)
+ contents <- inlineListToLaTeX lst
return $ "\\textsuperscript{" ++ contents ++ "}"
inlineToLaTeX (Subscript lst) = do
- contents <- inlineListToLaTeX (deVerb lst)
+ contents <- inlineListToLaTeX lst
-- oddly, latex includes \textsuperscript but not \textsubscript
-- so we have to define it:
addToHeader "\\newcommand{\\textsubscript}[1]{\\ensuremath{_{\\scriptsize\\textrm{#1}}}}"
return $ "\\textsubscript{" ++ contents ++ "}"
-inlineToLaTeX (Code str) = return $ "\\verb" ++ [chr] ++ stuffing ++ [chr]
- where stuffing = str
- chr = (('`':(enumFromTo '!' '~')) \\ stuffing) !! 0
+inlineToLaTeX (Code str) = return $ "\\Q{" ++ stuffing ++ "}"
+ where stuffing = concatMap (\c -> if isAlphaNum c
+ then [c]
+ else ['\\',c]) str
inlineToLaTeX (Quoted SingleQuote lst) = do
contents <- inlineListToLaTeX lst
let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
@@ -244,7 +243,6 @@ inlineToLaTeX (Image alternate (source, tit)) = do
addToHeader "\\usepackage{graphicx}"
return $ "\\includegraphics{" ++ source ++ "}"
inlineToLaTeX (Note contents) = do
- addToHeader "\\usepackage{fancyvrb}"
contents' <- blockListToLaTeX contents
return $ "\\footnote{" ++ stripTrailingNewlines contents' ++ "}"
diff --git a/src/headers/LaTeXHeader b/src/headers/LaTeXHeader
index 095848adf..125ab258e 100644
--- a/src/headers/LaTeXHeader
+++ b/src/headers/LaTeXHeader
@@ -1,5 +1,6 @@
\documentclass{article}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
+\usepackage[Q=yes,verbatimenv=yes,pverb-linebreak=no]{examplep}
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
diff --git a/src/wrappers/markdown2pdf.in b/src/wrappers/markdown2pdf.in
index c9a01fa16..7347fd7d7 100644
--- a/src/wrappers/markdown2pdf.in
+++ b/src/wrappers/markdown2pdf.in
@@ -40,9 +40,9 @@ fi
err "${THIS}: Please install the 'unicode' package from CTAN:"
err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
fi
- if grep -q "File \`fancyvrb.sty' not found" $texname.log; then
- err "${THIS}: Please install the 'fancyvrb' package from CTAN:"
- err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
+ if grep -q "File \`examplep.sty' not found" $texname.log; then
+ err "${THIS}: Please install the 'examplep' package from CTAN:"
+ err " http://www.ctan.org/tex-archive/macros/latex/contrib/examplep/"
fi
if grep -q "File \`ulem.sty' not found" $texname.log; then
err "${THIS}: Please install the 'ulem' package from CTAN:"