Undefined control sequence error while converting from markdown to PDF with pandoc and xelatex - latex

I'm making some documentation for our project, but I can't enable xelatex in pandoc to setup custom fonts. If I set --latex-engine xelatex pandoc will show that error:
pandoc: Error producing PDF from TeX source.
! Undefined control sequence.
l.17 \sys_if_engine_luatex:T
Here is a command that I run:
pandoc -s --latex-engine xelatex -f markdown build.md -o docs.pdf
I use Ubuntu 14.04 LTS, pandoc 1.12.2.1 and XeTeX, Version 3.1415926-2.5-0.9999.3 (TeX Live 2013/Debian).

Oops... after removing texlive 2013 with apt-get and installing manualy texlive 2015 pandoc will use old texlive (!!!). After that steps and setting PATH to /usr/local/texlive/2015/bin/x86_64-linux/ pandoc will finaly compile my file with xelatex.

Related

How can I provide packages to tex via nix?

I'm using nix to set up a little environment I can use for latex. I want to compile a small standalone document with tikz drawing. So I have this minimal tex file:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw(0,0)circle(8);
\end{tikzpicture}
\end{document}
This should need the pgf package for tikz and the standalone package for standalone. So I have my nix.shell
{ pkgs ? import <nixpkgs> {} }:
let
tex =
pkgs.texlive.combine
{ inherit (pkgs.texlive) scheme-minimal pgf standalone;
};
in
pkgs.mkShell
{ nativeBuildInputs =
[ tex
];
}
If I run my shell and attempt to compile with pdflatex:
[nix-shell:~/Projects/Tex]$ pdflatex example.tex
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021/NixOS.org) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./example.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-02-24>
! LaTeX Error: File `standalone.cls' not found.
It seems that latex is not aware of the packages, which isn't very surprising. But I don't really know how to do this. I've looked at texlive on the nixos wiki which doesn't say very much. They have an example which looks like what I have other than the fact it is using the home manager.
How do I make the packages installed via nix available for pdflatex?
I'm not sure why, but pdflatex is not available in scheme-minimal (even though pdftex is available). This can be verified with pure nix-shell:
$ nix-shell --pure
[nix-shell:~]$ pdflatex
The program 'pdflatex' is not in your PATH. It is provided by several packages.
You can make it available in an ephemeral shell by typing one of the following:
nix-shell -p tetex
nix-shell -p texlive.combined.scheme-basic
nix-shell -p texlive.combined.scheme-full
nix-shell -p texlive.combined.scheme-gust
nix-shell -p texlive.combined.scheme-medium
nix-shell -p texlive.combined.scheme-small
nix-shell -p texlive.combined.scheme-tetex
What happens in your case is that you run pdflatex from your main system, which does not have standalone available. If you change scheme-minimal to scheme-small, pdflatex will be available in the shell and everything will work.

How to use Latex to write Chinese documents in ArchLinux system?

I installed the following packages according to what ArchLinux officially said:
Archlinux TexLive
$ sudo pacman -S texlive-most texlive-langchinese
I compile it like this:
\documentclass[UTF8]{ctexart}
\begin{document}
中文文档类测试。
\end{document}
$ pdflatex demo.tex
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021/Arch Linux) (preloaded format=pdftex)
restricted \write18 enabled.
entering extended mode
(./demo.tex
! Undefined control sequence.
l.1 \documentclass
{ctexart}
?
! Undefined control sequence.
l.2 \begin
{document}
?
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] )</usr/share/texmf-dist/
fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on demo.pdf (1 page, 12721 bytes).
Transcript written on demo.log.
However, the result obtained is this:
Is this because I didn't add Chinese fonts? Or some other reason?
This problem is caused by my lack of understanding of the tex typesetting system.I used pdflatex directly which doesn't support Unicode character set, which is very stupid.Documents should be compiled with xelatex for the Unicode character set.

Unable to knit pdf from Rmardown from Rstudio in Windows 10 PC

I created a new Rmd file in the latest R and Rstudio version, and with the complete version of MiKTeX installed. In my windows 10 machine.
When I tried to knit it I got the following error
! LaTeX Error: File `fancyvrb.sty' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)
Enter file name:
! Emergency stop.
<read *>
l.34 \newcommand
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
Además: Warning message:
comando ejecutado '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS pdfprueba.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pdfprueba.pdf --template "C:\Users\karin\Documents\R\win-library\3.3\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' tiene estatus 43
Ejecución interrumpida
I suspected that it could have been that I didn't have the package fancyvrb in MiKTeX , so I followed these instructions but I still get the same error.
Try the same using
Miktex package manager (admin)
Under > repository check that your package repository is up to date.
In the name box type the name of your package
Then filter
then add your package
To test if your package is installed in dos CMD type
kpsewhich fancyvrb.sty. you should be able to see the path to your package.
Microsoft Windows [version 10.0.15063]
(c) 2017 Microsoft Corporation. Tous droits réservés.
C:\>kpsewhich fancyvrb.sty
C:/Users/me/AppData/Roaming/MiKTeX/2.9/tex/latex/fancyvrb/fancyvrb.sty

enable shell escape with pandoc

I'm trying to use the latex graphvis package in a pandoc markdown document. However it seems to require the -shell-escape flag be passed to latex. How can I enable -shell-escape on pandoc?
\digraph[scale=0.5]{MyGraph}{
Business -- Job;
Job -- Task;
Job -- User;
Job -- PayRate;
Task -- WorkSession;
User -- WorkSession;
PayRate -- WorkSession;
}
http://mark.aufflick.com/blog/2007/03/25/embedding-graphviz-in-latex-documents
pandoc can now pass arguments directly to the LaTeX engine via the --latex-engine-opt flag. As an example, in order to pass the -shell-escape flag to xelatex you could do:
pandoc myfile.md -s -o myfile.pdf --latex-engine=xelatex --latex-engine-opt=-shell-escape
You can tell pandoc to generate LaTeX, and then do whatever you want on the output.
pandoc -o mydocument.tex mydocument.md
pdflatex -shell-escape mydocument.tex
Pandoc has a --latex-engine option to tell it to run LaTeX differently, but this can only be a path to a program called pdflatex, lualatex or xelatex. If for some reason you want to be able to generate PDF from Markdown by calling pandoc directly, you can use a wrapper script.
pandoc --latex-engine=/path/to/pdflatex -o mydocument.pdf mydocument.md
where /path/to/pdflatex is executable and contains (assuming a Unix-like system)
#!/bin/sh
exec pdflatex -shell-escape "$#"

Markdown to PDF using Pandoc since Xetex Deprecation

On my MacBook (OSX Mountain Lion), I used to use this Pandoc command to convert Markdown to PDF:
$ markdown2pdf -N -o pandoc_output.pdf --xetex --toc --template=mytemplate.tex myfile.md
But markdown2pdf no longer works, and --xetex option in markdown2pdf -N -o ../../Desktop/pandoc_output.pdf --xetex --toc --template=mytemplate-headers-garamond_date.tex is deprecated.
If I do this:
$ pandoc -N -o Desktop/pandoc_output.pdf --xetex --toc --template=mytemplate.tex myfile.md
I get this:
pandoc: unrecognized option `--xetex'
But if I take out --xetex and do this:
$ pandoc -N -o Desktop/pandoc_output.pdf --toc --template=mytemplate.tex myfile.md
then I get this:
pandoc: Error producing PDF from TeX source.
! Package hyperref Error: Wrong driver option `xetex',
(hyperref) because XeTeX is not detected.
See the hyperref package documentation for explanation.
Type H <return> for immediate help.
...
l.3925 \ProcessKeyvalOptions{Hyp}
What's the solution?
Try --latex-engine=xelatex instead of --xetex
The prior answers to this question were helpful to me, as I had installed pandoc a couple years ago, but never Tex Live. Consequently I had no idea if I had installed it correctly, so putting in the entire path helped me to see that it was working, as follows:
pandoc --latex-engine=/usr/local/texlive/2012basic/bin/universal-darwin/xelatex
This is the default install location for the BasicTex setup which you download from the Pandoc install page.
I had also forgotten about using pandoc -D Latex >my-latex-template.tex to generate a template. After giving a .tex template instead of my .html one (which caused a 'you don't have BEGIN {' error) , I got .PDF: In other words, the default template worked.
Also, I had inaccurately entered -t pdf (not shown above) to set pdf as an output format, but this was not correct. The output format is Latex, which is then translated to PDF. It is not necessary to specify an output format with the dash -t option.
I hope this record of my minor stumbles saves someone some time.
See the pandoc User's Guide (or man page) for the --latex-engine option.

Resources