pandoc convert to pdf fails when € is in a header - pandoc

Windows 10 \euro in LaTeX
I have MiKTeX 2.9.6300 64-bit, and I can xelatex eurosym where eurosym.tex contains the following LaTeX code:
\documentclass{article}
\usepackage{eurosym}
\begin{document}
\section{2\euro{}} % (this line fails if eurosym package isn't called)
2€ % (this € symbol is lost if compiled with pdflatex instead of xelatex)
\end{document}
- output is as expected:
Pandoc on Win10 eurosym call fails
My local copy of pandoc-templates/default.latex correctly contains the call:
$if(euro)$
\usepackage{eurosym}
$endif$
And I have pandoc v1.19.2.1 installed, so I would expect pandoc eurosym.md -o eurosym.pdf --latex-engine=xelatex to work when eurosym.md contains just:
# 2€
2€
- but in fact I get:
! Improper alphabetic constant.
<to be read again>
\euro
l.70 \section{2\euro{}}
pandoc.exe: Error producing PDF
- why is the command \euro{} failing here in Pandoc?
same with Pandoc on Arch Linux
pandoc 1.19.2.1-90, calling texlive-bin 2016.41290-12, and using jgm's default.latex I get:
! Improper alphabetic constant.
<to be read again>
\euro
l.35 \section{2\euro{}}
pandoc: Error producing PDF
But I can get it to work as expected by commenting out line 76, \usepackage[unicode=true]{hyperref} (and then lines 80-98 and line 253, both \hypersetup{...} clauses, and line 99, \urlstyle{same} which require hyperref) of jgm's default.latex.
Discovering that there is a more current default.latex, I tried with that one, and Pandoc failed on \euro again.
Conclusion appear to be that somehow eurosym & hyperref are mutually incompatible in Pandoc
So I've created a New Issue: eurosym in Pandoc seems to be incompatible with hyperref #3801.

You must use \usepackage{eurosym} only with pdflatex. XeLaTeX is unicode-aware and you can just use the euro symbol directly.
The default pandoc template therefore wraps is in a an "if pdftex", which you might have missed when modifying your template:
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
...
$if(euro)$
\usepackage{eurosym}
$endif$
...
\fi

Related

pandoc: "No such file or directory" when converting file with Unicode characters in filename

Using the pandoc tool on Windows 11, I am trying to convert to HTML a Markdown file with Unicode characters in its name with the following command:
pandoc -f markdown_phpextra -o 'Ahoj sv─¢te.html' 'Ahoj sv─¢te.md'
But pandoc complains with the following error:
[WARNING] Could not deduce format from file extension
Defaulting to html
pandoc.exe: svÄ>te.html': openBinaryFile: does not exist (No such file or directory)
Any ideas how to make pandoc understand the filenames containing Unicode characters correctly?
Executing the chcp 65001 command before running the pandoc command solved the issue. Thanks #tarleb for providing this suggestion.

Not able to use titlesec with markdown and pandoc?

When I used titlesec in my markdown document as below:
---
header-includes:
- \usepackage{titlesec}
---
when processing it by pandoc, I got the following error:
pandoc try.md -o try.pdf
! Argument of \paragraph has an extra }.
<inserted text>
\par
l.1290 \ttl#extract\paragraph
pandoc: Error producing PDF
by searching, I found the following work-around for R-markdown:
Can't knit to pdf with custom styles
I wonder how can I implement a similar work-around with markdown and YAML headers?
I also found and verified the following approach would work:
pandoc --variable=subparagraph try.md -o try.pdf
But it's harder for the user, as one might forget the work-around.
There are some discussion of the work-around https://www.bountysource.com/issues/40574981-latex-template-incompatible-with-titlesec,
but it's beyond my knowledge
Thanks for your help
This is because the default LaTeX template redefines \paragraph. To disable this behaviour, you can use the subparagraph variable in pandoc. You could supply this at the command-line:
pandoc --variable subparagraph -o file.pdf file.md
Or you could embed it in the document's YAML metadata, with any non-null value:
---
subparagraph: yes
---
From man pandoc (and the user's guide):
subparagraph
disables default behavior of LaTeX template that redefines (sub)paragraphs as sections, changing the appearance of nested headings in some classes
After this, titlesec.sty should work.

Running lua file: unexpected symbol near char(226)

I'm doing a tutorial on learning lua: https://www.lua.org/pil/1.html
I'm trying to open a simple file called hello.lua that I created with Textedit, located in the folder "luaProjects". The file contains the following line:
print("Hello World")
I get an error however, when I try to run the hello world script like this:
luaProjects username$ lua hello.lua
lua: hello.lua:1: unexpected symbol near char(226)
I think that lua is installed correctly:
User-MacBook-Air:~ username$ lua -v
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
And I think that I have set the folder and file up correctly:
User-MacBook-Air:luaProjects username$ tree
.
└── hello.lua
0 directories, 1 file
Q: Does anyone know how to fix this?
It could be that your double quotation marks are not ascii, but unicode left/right double quotation marks. Those start with 0xe2, exactly yours 226.
Try some simpler editor, or explicitly save file as ascii.
Avoid saving lua code files as unicode and convert your existing files via:
iconv -f utf-8 -t ascii YOURFILE

Why can't I include images in pdf using Pandoc?

I can successfully produce the images when output is HTML, but errors out when attempting pdf output.
input file text for image,
![](images\icon.png "test")
Error produced,
pandoc: Error producing PDF from TeX source.
! Undefined control sequence.
images\icon
l.535 \includegraphics{images\icon.png}
Note that pandoc produces the PDF via LaTeX, as the error message reveals. Your input
![](images\icon.png "test")
is converted into LaTeX
\includegraphics{images\icon.png}
\ in LaTeX has a special meaning: it begins a control sequence. So LaTeX is looking for an \icon command here and not finding it. The fix is to use a forward slash / instead of a backslash \ as path separator. LaTeX allows you to use / for paths even in Windows.
Of course, this may cause problems in some other output formats. I suppose I should change pandoc to convert backslashes in paths to forward slashes when writing LaTeX.
I've had a similar problem on Windows. My images are stored in a subdirectory named "figures". No matter what I tried the path wasn't followed. I have solved it by including --resource-path=.;figures in the call to pandoc.

How to execute shell script from LaTeX?

I'm trying to do the following in LaTeX:
\documentclass{article}
\begin{document}
\execute{/usr/local/bin/my-shell-script.sh}
\end{document}
The idea is to execute /usr/local/bin/my-shell-script.sh at the moment of .tex document processing and inject its output into LaTeX stream. Is it possible at all?
PS. It's possible through the package I've made: iexec
I would do something like the following (partially motivated by what Roman suggested): make your LaTeX file be
\documentclass{article}
\begin{document}
\input{scriptoutput.tex}
\end{document}
and generate the file scriptoutput.tex using
/usr/local/bin/my-shell-script.sh > scriptoutput.tex
You could encode this in a makefile if you want to have it run automatically when necessary. Alternatively, you could use the TeX \write18 command,
\documentclass{article}
\immediate\write18{/usr/local/bin/my-shell-script.sh > scriptoutput.tex}
\begin{document}
\input{scriptoutput.tex}
\end{document}
and I think that would automatically run the shell script each time you compile the document. The \immediate is necessary to ensure that the script is run when LaTeX encounters the command, rather than waiting until a page of output is written. (See this question for more on the shipout routine.)
As David pointed out, you can use \write18 to call external programs, then \input the resultant output file. However you will probably want to use \immediate\write18 to make sure the script is executed before calling the \input.
Alternatively, if you use newer versions of pdf(la)tex (after 1.40, I think), you can pipe the output directly into the document, by using a piped input command:
\documentclass{article}
\begin{document}
\input{|"/usr/local/bin/my-shell-script.sh"}
\end{document}
For either method you will need to enable external program calls. For TeXlive distributions, you need to call latex with the -shell-escape option, or for MikTeX, I believe the option is -enable-write18.
You can do this in TeX. This paper (PDF) shows you how to write and execute a virus within TeX. The same principles apply for executing a shell script. However in my opinion it is more practicable to write a Makefile, which runs before your LaTeX run and inserts the result.
On Ubuntu 11.10 GNU/Linux
pdflatex --enable-pipes --shell-escape mytexfile
with
%...
[This section currently is
\input{|"wc kmb-box.tex| tr -s ' ' | cut -d' ' -f 4"}
% 2000 characters are allowed here
\input{kmb-box}
%...
works nicely. ie, this uses wordcount (wc) to report how many characters are in the file kmb-box.tex, which is part of (included in) the document.
(btw If you wanted words rather than characters, just change the number in "-f 4")
Unless it is imperative that the script is run while LaTeX is running I would recommend just using make to run LaTeX and you script.
I have used that approach to add word counting for articles and including statistics on bibliographic references.
Let your script generate a .tex file and include that in you LaTeX source file.
Below is a snippet from one of my Makefiles:
TEX = /usr/texbin/pdflatex
PREVIEW = /usr/bin/open
REPORT = SimMon
REPORT_MASTER = $(REPORT).tex
TEX_OPTIONS = -halt-on-error
SimMon: $(REPORT_MASTER) countRefferedPages
$(TEX) $(TEX_OPTIONS) $(REPORT_MASTER)
#$(PREVIEW) $(REPORT).pdf
countRefferedPages: BibTeXPageCount
cat *.tex | support/BPC/build/Debug/BPC Castle.bib > litteraturTotal.tex
This is how I do it with my own iexec package:
\documentclass{article}
\usepackage{iexec}
\begin{document}
\iexec{/usr/local/bin/my-shell-script.sh}
\end{document}
When the output is not required, I can do just this:
\iexec[quiet]{/usr/local/bin/my-shell-script.sh}

Resources