Pandoc: Cannot set papersize to A4 when converting markdown to PDF via LaTeX

Created on 14 Jun 2016  Â·  6Comments  Â·  Source: jgm/pandoc

Maybe I'm making some silly mistake, but I can't seem to configure the papersize when converting from markdown to PDF via LaTeX. It always comes out as letter...

MWE with CLI papersize variable:

$ cat > bare.md <<EOF
> # Fnord
> EOF
$ pandoc -V papersize:a4paper bare.md --output=bare.pdf
$ pdfinfo bare.pdf | grep 'Page size'
Page size:      612 x 792 pts (letter)

MWE with papersize in YAML header:

$ cat > yaml.md <<EOF
> ---
> papersize: a4paper
> ...
> # Fnord
> EOF
$ pandoc yaml.md --output=yaml.pdf
$ pdfinfo yaml.pdf | grep 'Page size'
Page size:      612 x 792 pts (letter)

I'm using

$ pandoc --version
pandoc 1.17.1
Compiled with texmath 0.8.6.3, highlighting-kate 0.6.2.
Syntax highlighting is supported for the following languages:
    abc, actionscript, ada, agda, apache, asn1, asp, awk, bash, bibtex, boo, c,
    changelog, clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css,
    curry, d, diff, djangotemplate, dockerfile, dot, doxygen, doxygenlua, dtd,
    eiffel, elixir, email, erlang, fasm, fortran, fsharp, gcc, glsl,
    gnuassembler, go, hamlet, haskell, haxe, html, idris, ini, isocpp, java,
    javadoc, javascript, json, jsp, julia, kotlin, latex, lex, lilypond,
    literatecurry, literatehaskell, llvm, lua, m4, makefile, mandoc, markdown,
    mathematica, matlab, maxima, mediawiki, metafont, mips, modelines, modula2,
    modula3, monobasic, nasm, noweb, objectivec, objectivecpp, ocaml, octave,
    opencl, pascal, perl, php, pike, postscript, prolog, pure, python, r,
    relaxng, relaxngcompact, rest, rhtml, roff, ruby, rust, scala, scheme, sci,
    sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, tcsh, texinfo, verilog, vhdl,
    xml, xorg, xslt, xul, yacc, yaml, zsh
Default user data directory: /Users/ingmar/.pandoc
Copyright (C) 2006-2016 John MacFarlane
Web:  http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

Installed via homebrew on OSX 10.9.5.

Any help would be appreciated!

Most helpful comment

Have a look at the default latex template and you'll see what is going on here.

\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$paper,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}

Note that the value of papersize gets appended to paper. So, if you set papersize to a4paper, the latex generated has a4paperpaper. The solution is to set the papersize variable to a4.

Why do we do it this way? So the same source document will work with LaTeX or ConTeXt or other formats that want a4 rather than a4paper.

All 6 comments

I can confirm that the workaround via geometry suggested by @yoavram in #600 _does_ produce the desired output:

$ cat > geometry.md <<EOF
> ---
> geometry: a4paper
> ...
> # Fnord
> EOF
$ pandoc geometry.md --output=geometry.pdf
$ pdfinfo geometry.pdf | grep 'Page size'
Page size:      595.276 x 841.89 pts (A4)

But I'm confused because the official documentation indicates that the regular papersize variable should work as well, at least since jgm/pandoc-templates#15.

Have a look at the default latex template and you'll see what is going on here.

\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$paper,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}

Note that the value of papersize gets appended to paper. So, if you set papersize to a4paper, the latex generated has a4paperpaper. The solution is to set the papersize variable to a4.

Why do we do it this way? So the same source document will work with LaTeX or ConTeXt or other formats that want a4 rather than a4paper.

@jgm Of course, that makes perfect sense. Thank you for the explanation (and for an awesome tool)!

Just fyi anyone who tries to set papersize to A5 (or whatever), it is case sensitive so you need to do a5 instead.

I'll change this so that Ax is case-insensitive for any x.

+++ Dylan Chong [Nov 29 17 08:07 ]:

Just fyi anyone who tries to set papersize to A5 (or whatever), it is
case sensitive so you need to do a5 instead.

—
You are receiving this because you were mentioned.
Reply to this email directly, [1]view it on GitHub, or [2]mute the
thread.

References

  1. https://github.com/jgm/pandoc/issues/2982#issuecomment-347782973
  2. https://github.com/notifications/unsubscribe-auth/AAAL5Oen3VYjcbHNBi3TkDRnqm2Cttuaks5s7RDRgaJpZM4I1cq9

Can you also change it so that it notices the user if they try to use "--var papersize:a4paper"? I have several old makefiles that use that option from when it used to work and I got very confused when some documents compiled to more pages than before, then I realized it was using letter paper.

(maybe stripping "paper" could be something to think about)

Was this page helpful?
0 / 5 - 0 ratings