Running this shell skript:

#!/bin/bash -e
pandoc --top-level-division=chapter -V geometry:"margin=0.8in, landscape" --toc -s $FILE -o ${FILE%.*}.pdf

with this minimal LaTeX file:


gives me:

Error producing PDF.
! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

l.64 \documentclass

Any hints on this? I am new to LaTeX and have no clue why this is not working.

  • 1
    Welcome to TeX.SX! You can help us to help you by providing the code for a small compilable document that shows your problem called MWE. Just edit your question and add missing code.
    – Bobyandbob
    Mar 1, 2018 at 13:39
  • 1
    It looks like you are trying to use pandoc to convert a LaTeX file to PDF. Instead, use LaTeX to do this: pdflatex file. The script you've written should work for converting a Markdown file to PDF. (Pandoc uses LaTeX to create the PDF but you don't have to write any LaTeX code for basic documents.) Mar 1, 2018 at 13:54
  • 2
    In other words, if you run Pandoc on a LaTeX file in this way, it will create another LaTeX file with the necessary preamble and then include your LaTeX file inside it, which is why you are getting this error: the document Pandoc is creating includes your preamble commands in the body, not the preamble. Mar 1, 2018 at 13:58
  • What did you do in the end, Michael?
    – Keks Dose
    Mar 15, 2018 at 15:02
  • Solution was using pandoc the correct way. Not mixing it with LaTeX code. As you guys told me. Mar 16, 2018 at 13:24

1 Answer 1


This is a misunderstanding. If you have got a kind of TeX system running (usually texlive or MiKTeX), save your LaTeX-file as (e.g.) foo.tex and run pdflatex foo.tex and you'll probably get foo.pdfas result.

pdflatex --help displays help in a nutshell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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