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
are not already included in your LaTeX distribution):
+ `unicode` (for UTF8 characters)
+ `fancyvrb` (for verbatim text in footnotes)
+ `examplep` (for verbatim text in footnotes and definition lists)
+ `graphicx` (for images)
+ `array` (for tables)
+ `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)
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,
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
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.
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
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:
@ -499,11 +500,13 @@ after the term. The definition consists of one or more block elements
Term *with inline markup*
: Here is the definition. It may
contain multiple blocks. Here is some code:
contain multiple blocks. Here is
some 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),
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]
[^1]: Here is the footnote. It can go anywhere in the document,
except in embedded contexts like block quotes or lists.
[^1]: Here is the footnote.
[^longnote]: Here's the other note. This one contains multiple
blocks.
[^longnote]: Here's one with multiple blocks.
Subsequent paragraphs are indented to show that they belong to
the previous footnote.
Subsequent paragraphs are indented to show
that they belong to the previous footnote.
{ some.code }
The whole paragraph can be indented, or just the first line.
In this way, multi-paragraph footnotes work just like
multi-paragraph list items in markdown.
The whole paragraph can be indented, or
just the first line. In this way,
multi-paragraph footnotes work like
multi-paragraph list items.
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
of text. Here is an example:
---------------------------------------------------------------
Centered Left Right
Header Aligned Aligned Default aligned
---------- --------- ----------- ---------------------------
First row 12.0 Example of a row that spans
multiple lines.
----------------------------------------
Centered Left-aligned Right-aligned
Header Header Header
---------- ------------- --------------
First This is a 12.0
two-line row.
Second This row is 5.0
three lines
long.
----------------------------------------
Second row 5.0 Here's another one. Note
the blank line between rows.
---------------------------------------------------------------
Table: Optional caption. This, too, may span multiple
lines.
Table: Optional caption. This, too,
may span multiple lines.
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.
- Convert all alphabetic characters to lowercase.
Thus,
Header text Identifier
--------------------------------- --- --------------------------------
Header identifiers in HTML → `header-identifiers-in-html`
*Dogs*?--in *my* house? → `dogs--in-my-house`
[HTML], [S5], or [RTF]? → `html-s5-or-rtf`
Thus, for example, a heading 'Header identifiers in HTML' will get
the identifier `header-identifiers-in-html`, a heading
'*Dogs*?--in *my* house?' will get the identifier `dogs--in-my-house`,
and a heading '[HTML], [S5], or [RTF]?' will get the identifier
`html-s5-or-rtf`.
These rules should, in most cases, allow one to determine the identifier
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
Architecture: any
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
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

View file

@ -28,7 +28,7 @@ output through `iconv`:
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
packages are not included in your latex setup, they can be obtained from
<http://ctan.org>.

View file

@ -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' ++ "}"

View file

@ -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}

View file

@ -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:"

View file

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