Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know that I can use the -H or --include-in-header commands to include a custom preamble in the generated output. The problem is now that Pandoc includes my preamble but puts another preamble in front of it:

\documentclass{article}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifxetex
  \usepackage{fontspec,xltxtra,xunicode}
  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\else
  \ifluatex
    \usepackage{fontspec}
    \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
  \else
    \usepackage[utf8]{inputenc}
  \fi
\fi
\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex]{hyperref}
\else
  \usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true, pdfborder={0 0 0}}
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\setcounter{secnumdepth}{0}

[... my preamble ...]

I know that this is the default LaTeX preamble (default.latex) that Pandoc loads from its templates folder. The same thing happens when I'm using --include-after-body with \end{document}.

This is the command I'm using:

pandoc -o output.tex input.txt --include-before-body=header.tex --include-after-body=footer.tex
share|improve this question
add comment

1 Answer

As you have discovered, --include-in-header adds text into the preamble specified in Pandoc's LaTeX template. There are a few ways to do what you are trying to do.

  1. If you would like a completely custom preamble, you need to specify a template file using

    pandoc -o output.tex --template=FILE input.txt
    

The template can have variables (such as $title$ and, more importantly, $body) and conditionals. If you would like some inspiration, you could check out the default template using the command

    pandoc -D latex
  1. If you want to use a new template once and for all, you can make one, call it default.latex, and put it in the templates directory (~/.pandoc/templates/ on a unix machine). In this case, you need to specify that you want to use a template by calling

    pandoc -o output.tex --standalone input.txt
    
  2. If you would rather not deal with templates at all, you can just run

    pandoc -o output.tex input.txt
    

and the result will be a bare LaTeX document, that is, without a preamble, \begin{document} or \end{document}. Then you can add a preamble yourself. Note that any metadata (title, author) will be lost when using this method.

Full details on how to make and use templates can be found in Pandoc's excellent man page.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.