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
This commit is contained in:
fiddlosopher 2007-07-28 01:10:04 +00:00
parent 4283ce3662
commit b29f221cba
7 changed files with 58 additions and 57 deletions

69
README
View file

@ -59,7 +59,7 @@ The wrapper script `markdown2pdf` requires
- the following LaTeX packages (available from [CTAN], if they - the following LaTeX packages (available from [CTAN], if they
are not already included in your LaTeX distribution): are not already included in your LaTeX distribution):
+ `unicode` (for UTF8 characters) + `unicode` (for UTF8 characters)
+ `fancyvrb` (for verbatim text in footnotes) + `examplep` (for verbatim text in footnotes and definition lists)
+ `graphicx` (for images) + `graphicx` (for images)
+ `array` (for tables) + `array` (for tables)
+ `ulem` (for strikeout text) + `ulem` (for strikeout text)
@ -85,7 +85,7 @@ Note that you can specify multiple input files on the command line.
`pandoc` will concatenate them all (with blank lines between them) `pandoc` will concatenate them all (with blank lines between them)
before parsing: before parsing:
pandoc -s chapter1.txt chapter2.txt references.txt > book.html pandoc -s ch1.txt ch2.txt refs.txt > book.html
(The `-s` option here tells `pandoc` to produce a standalone HTML file, (The `-s` option here tells `pandoc` to produce a standalone HTML file,
with a proper header, rather than a fragment. For more details on this with a proper header, rather than a fragment. For more details on this
@ -167,7 +167,7 @@ may be used in Windows under Cygwin.)
it will be backed up before being overwritten.) An output file it will be backed up before being overwritten.) An output file
name can be specified explicitly using the `-o` option: name can be specified explicitly using the `-o` option:
markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt markdown2pdf -o book.pdf chap1 chap2
If no input file is specified, input will be taken from STDIN. If no input file is specified, input will be taken from STDIN.
All of `pandoc`'s options will work with `markdown2pdf` as well. All of `pandoc`'s options will work with `markdown2pdf` as well.
@ -340,7 +340,8 @@ For further documentation, see the `pandoc(1)` man page.
include the names of input files and any special options passed include the names of input files and any special options passed
after ` -- ` on the command line. So, for example, after ` -- ` on the command line. So, for example,
: pandoc --dump-args -o foo.html -s foo.txt appendix.txt -- -e latin1 : pandoc --dump-args -o foo.html -s foo.txt \
appendix.txt -- -e latin1
: will cause the following to be printed to STDOUT: : will cause the following to be printed to STDOUT:
@ -499,11 +500,13 @@ after the term. The definition consists of one or more block elements
Term *with inline markup* Term *with inline markup*
: Here is the definition. It may : Here is the definition. It may
contain multiple blocks. Here is some code: contain multiple blocks. Here is
some code:
: {* my code *} : {* my code *}
: Here is the third paragraph of this definition. : Here is the third paragraph of this
definition.
If you leave space after the definition (as in the first example above), If you leave space after the definition (as in the first example above),
the definitions will be considered paragraphs. In some output formats, the definitions will be considered paragraphs. In some output formats,
@ -537,20 +540,19 @@ Pandoc's markdown allows footnotes, using the following syntax:
Here is a footnote reference,[^1] and another.[^longnote] Here is a footnote reference,[^1] and another.[^longnote]
[^1]: Here is the footnote. It can go anywhere in the document, [^1]: Here is the footnote.
except in embedded contexts like block quotes or lists.
[^longnote]: Here's the other note. This one contains multiple [^longnote]: Here's one with multiple blocks.
blocks.
Subsequent paragraphs are indented to show that they belong to Subsequent paragraphs are indented to show
the previous footnote. that they belong to the previous footnote.
{ some.code } { some.code }
The whole paragraph can be indented, or just the first line. The whole paragraph can be indented, or
In this way, multi-paragraph footnotes work just like just the first line. In this way,
multi-paragraph list items in markdown. multi-paragraph footnotes work like
multi-paragraph list items.
This paragraph won't be part of the note, because it isn't indented. This paragraph won't be part of the note, because it isn't indented.
@ -616,19 +618,20 @@ try widening it in the markdown source.
Multiline tables allow headers and table rows to span multiple lines Multiline tables allow headers and table rows to span multiple lines
of text. Here is an example: of text. Here is an example:
--------------------------------------------------------------- ----------------------------------------
Centered Left Right Centered Left-aligned Right-aligned
Header Aligned Aligned Default aligned Header Header Header
---------- --------- ----------- --------------------------- ---------- ------------- --------------
First row 12.0 Example of a row that spans First This is a 12.0
multiple lines. two-line row.
Second This row is 5.0
three lines
long.
----------------------------------------
Second row 5.0 Here's another one. Note Table: Optional caption. This, too,
the blank line between rows. may span multiple lines.
---------------------------------------------------------------
Table: Optional caption. This, too, may span multiple
lines.
These work like simple tables, but with the following differences: These work like simple tables, but with the following differences:
@ -734,13 +737,11 @@ derive the identifier from the header text,
- Replace all spaces, dashes, newlines, and hyphens with hyphens. - Replace all spaces, dashes, newlines, and hyphens with hyphens.
- Convert all alphabetic characters to lowercase. - Convert all alphabetic characters to lowercase.
Thus, Thus, for example, a heading 'Header identifiers in HTML' will get
the identifier `header-identifiers-in-html`, a heading
Header text Identifier '*Dogs*?--in *my* house?' will get the identifier `dogs--in-my-house`,
--------------------------------- --- -------------------------------- and a heading '[HTML], [S5], or [RTF]?' will get the identifier
Header identifiers in HTML → `header-identifiers-in-html` `html-s5-or-rtf`.
*Dogs*?--in *my* house? → `dogs--in-my-house`
[HTML], [S5], or [RTF]? → `html-s5-or-rtf`
These rules should, in most cases, allow one to determine the identifier These rules should, in most cases, allow one to determine the identifier
from the header text. The exception is when several headers have the from the header text. The exception is when several headers have the

2
debian/control vendored
View file

@ -10,7 +10,7 @@ Package: pandoc
Section: text Section: text
Architecture: any Architecture: any
Depends: ${shlibs:Depends} Depends: ${shlibs:Depends}
Suggests: texlive-latex-recommended | tetex-extra, tidy, wget | w3m Suggests: texlive-latex-recommended | tetex-extra, texlive-latex-extra, tidy, wget | w3m
Description: general markup converter Description: general markup converter
Pandoc is a Haskell library for converting from one markup format to Pandoc is a Haskell library for converting from one markup format to
another, and a command-line tool that uses this library. It can read another, and a command-line tool that uses this library. It can read

View file

@ -28,7 +28,7 @@ output through `iconv`:
iconv -t utf-8 input.txt | pandoc | iconv -f utf-8 iconv -t utf-8 input.txt | pandoc | iconv -f utf-8
`markdown2pdf` assumes that the `unicode`, `fancyvrb`, `array`, `markdown2pdf` assumes that the `unicode`, `examplep`, `array`,
`graphicx`, and `ulem` packages are in latex's search path. If these `graphicx`, and `ulem` packages are in latex's search path. If these
packages are not included in your latex setup, they can be obtained from packages are not included in your latex setup, they can be obtained from
<http://ctan.org>. <http://ctan.org>.

View file

@ -34,6 +34,7 @@ import Text.Pandoc.Definition
import Text.Pandoc.Shared import Text.Pandoc.Shared
import Text.Printf ( printf ) import Text.Printf ( printf )
import Data.List ( (\\), isInfixOf ) import Data.List ( (\\), isInfixOf )
import Data.Char ( isAlphaNum )
import qualified Data.Set as S import qualified Data.Set as S
import Control.Monad.State import Control.Monad.State
@ -81,15 +82,12 @@ latexHeader options (Meta title authors date) = do
then "" then ""
else "\\date{" ++ stringToLaTeX date ++ "}\n" else "\\date{" ++ stringToLaTeX date ++ "}\n"
let maketitle = if null title then "" else "\\maketitle\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) let secnumline = if (writerNumberSections options)
then "" then ""
else "\\setcounter{secnumdepth}{0}\n" else "\\setcounter{secnumdepth}{0}\n"
let baseHeader = writerHeader options let baseHeader = writerHeader options
let header = baseHeader ++ extras let header = baseHeader ++ extras
return $ header ++ secnumline ++ verbatim ++ titletext ++ authorstext ++ return $ header ++ secnumline ++ titletext ++ authorstext ++
datetext ++ "\\begin{document}\n" ++ maketitle ++ "\n" datetext ++ "\\begin{document}\n" ++ maketitle ++ "\n"
-- escape things as needed for LaTeX -- escape things as needed for LaTeX
@ -106,11 +104,11 @@ stringToLaTeX = escapeStringUsing latexEscapes
] ]
-- | Remove all code elements from list of inline elements -- | 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 :: [Inline] -> [Inline]
deVerb [] = [] deVerb [] = []
deVerb ((Code str):rest) = deVerb ((Code str):rest) =
(Str $ stringToLaTeX str):(deVerb rest) (TeX $ "\\texttt{" ++ stringToLaTeX str ++ "}"):(deVerb rest)
deVerb (other:rest) = other:(deVerb rest) deVerb (other:rest) = other:(deVerb rest)
-- | Convert Pandoc block element to LaTeX. -- | Convert Pandoc block element to LaTeX.
@ -155,7 +153,7 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
AlignCenter -> "\\centering" AlignCenter -> "\\centering"
AlignDefault -> "\\raggedright") ++ AlignDefault -> "\\raggedright") ++
"\\hspace{0pt}}p{" ++ width ++ "\\hspace{0pt}}p{" ++ width ++
"\\textwidth}") "\\columnwidth}")
colWidths aligns colWidths aligns
let tableBody = "\\begin{tabular}{" ++ colDescriptors ++ "}\n" ++ let tableBody = "\\begin{tabular}{" ++ colDescriptors ++ "}\n" ++
headers ++ "\\hline\n" ++ concat rows' ++ "\\end{tabular}\n" headers ++ "\\hline\n" ++ concat rows' ++ "\\end{tabular}\n"
@ -177,7 +175,7 @@ tableRowToLaTeX cols =
listItemToLaTeX lst = blockListToLaTeX lst >>= (return . ("\\item "++)) listItemToLaTeX lst = blockListToLaTeX lst >>= (return . ("\\item "++))
defListItemToLaTeX (term, def) = do defListItemToLaTeX (term, def) = do
term' <- inlineListToLaTeX (deVerb term) term' <- inlineListToLaTeX term
def' <- blockListToLaTeX def def' <- blockListToLaTeX def
return $ "\\item[" ++ term' ++ "] " ++ def' return $ "\\item[" ++ term' ++ "] " ++ def'
@ -196,27 +194,28 @@ isQuoted _ = False
inlineToLaTeX :: Inline -- ^ Inline to convert inlineToLaTeX :: Inline -- ^ Inline to convert
-> State WriterState String -> State WriterState String
inlineToLaTeX (Emph lst) = do inlineToLaTeX (Emph lst) = do
contents <- inlineListToLaTeX (deVerb lst) contents <- inlineListToLaTeX lst
return $ "\\emph{" ++ contents ++ "}" return $ "\\emph{" ++ contents ++ "}"
inlineToLaTeX (Strong lst) = do inlineToLaTeX (Strong lst) = do
contents <- inlineListToLaTeX (deVerb lst) contents <- inlineListToLaTeX lst
return $ "\\textbf{" ++ contents ++ "}" return $ "\\textbf{" ++ contents ++ "}"
inlineToLaTeX (Strikeout lst) = do inlineToLaTeX (Strikeout lst) = do
contents <- inlineListToLaTeX (deVerb lst) contents <- inlineListToLaTeX lst
addToHeader "\\usepackage[normalem]{ulem}" addToHeader "\\usepackage[normalem]{ulem}"
return $ "\\sout{" ++ contents ++ "}" return $ "\\sout{" ++ contents ++ "}"
inlineToLaTeX (Superscript lst) = do inlineToLaTeX (Superscript lst) = do
contents <- inlineListToLaTeX (deVerb lst) contents <- inlineListToLaTeX lst
return $ "\\textsuperscript{" ++ contents ++ "}" return $ "\\textsuperscript{" ++ contents ++ "}"
inlineToLaTeX (Subscript lst) = do inlineToLaTeX (Subscript lst) = do
contents <- inlineListToLaTeX (deVerb lst) contents <- inlineListToLaTeX lst
-- oddly, latex includes \textsuperscript but not \textsubscript -- oddly, latex includes \textsuperscript but not \textsubscript
-- so we have to define it: -- so we have to define it:
addToHeader "\\newcommand{\\textsubscript}[1]{\\ensuremath{_{\\scriptsize\\textrm{#1}}}}" addToHeader "\\newcommand{\\textsubscript}[1]{\\ensuremath{_{\\scriptsize\\textrm{#1}}}}"
return $ "\\textsubscript{" ++ contents ++ "}" return $ "\\textsubscript{" ++ contents ++ "}"
inlineToLaTeX (Code str) = return $ "\\verb" ++ [chr] ++ stuffing ++ [chr] inlineToLaTeX (Code str) = return $ "\\Q{" ++ stuffing ++ "}"
where stuffing = str where stuffing = concatMap (\c -> if isAlphaNum c
chr = (('`':(enumFromTo '!' '~')) \\ stuffing) !! 0 then [c]
else ['\\',c]) str
inlineToLaTeX (Quoted SingleQuote lst) = do inlineToLaTeX (Quoted SingleQuote lst) = do
contents <- inlineListToLaTeX lst contents <- inlineListToLaTeX lst
let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else "" let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
@ -244,7 +243,6 @@ inlineToLaTeX (Image alternate (source, tit)) = do
addToHeader "\\usepackage{graphicx}" addToHeader "\\usepackage{graphicx}"
return $ "\\includegraphics{" ++ source ++ "}" return $ "\\includegraphics{" ++ source ++ "}"
inlineToLaTeX (Note contents) = do inlineToLaTeX (Note contents) = do
addToHeader "\\usepackage{fancyvrb}"
contents' <- blockListToLaTeX contents contents' <- blockListToLaTeX contents
return $ "\\footnote{" ++ stripTrailingNewlines contents' ++ "}" return $ "\\footnote{" ++ stripTrailingNewlines contents' ++ "}"

View file

@ -1,5 +1,6 @@
\documentclass{article} \documentclass{article}
\usepackage{ucs} \usepackage{ucs}
\usepackage[utf8x]{inputenc} \usepackage[utf8x]{inputenc}
\usepackage[Q=yes,verbatimenv=yes,pverb-linebreak=no]{examplep}
\setlength{\parindent}{0pt} \setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt} \setlength{\parskip}{6pt plus 2pt minus 1pt}

View file

@ -40,9 +40,9 @@ fi
err "${THIS}: Please install the 'unicode' package from CTAN:" err "${THIS}: Please install the 'unicode' package from CTAN:"
err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/" err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
fi fi
if grep -q "File \`fancyvrb.sty' not found" $texname.log; then if grep -q "File \`examplep.sty' not found" $texname.log; then
err "${THIS}: Please install the 'fancyvrb' package from CTAN:" err "${THIS}: Please install the 'examplep' package from CTAN:"
err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/" err " http://www.ctan.org/tex-archive/macros/latex/contrib/examplep/"
fi fi
if grep -q "File \`ulem.sty' not found" $texname.log; then if grep -q "File \`ulem.sty' not found" $texname.log; then
err "${THIS}: Please install the 'ulem' package from CTAN:" err "${THIS}: Please install the 'ulem' package from CTAN:"

View file

@ -1,4 +1,5 @@
\documentclass[12pt]{article} \documentclass[twocolumn,11pt]{article}
\usepackage{txfonts} \usepackage{txfonts}
\usepackage[margin=2cm]{geometry}
\usepackage{ucs} \usepackage{ucs}
\usepackage[utf8x]{inputenc} \usepackage[utf8x]{inputenc}