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 "$#"
Related
I am trying to use pandoc to convert a thesis from latex to docx. In general, this works well with the following command:
pandoc input.tex -f latex -t docx -s -o output.docx --bibliography references.bib --csl=mystyle.csl
However, I have an additional requirement that I am unable to fulfill. I want the output to be stripped from any figures and tables that are included in the source files. Reading the pandoc documentation and related stackoverflow question has not helped me so far.
Do you have suggestions on what could do the trick?
This is a poster use-case for pandoc filters. The following Lua filter will delete all tables and images:
function Image () return {} end
function Table () return {} end
Save it to a file, say remove-tables-images.lua, and pass the file to pandoc via the --lua-filter parameter:
pandoc input.tex -s -o output.docx \
--bibliography references.bib --csl=mystyle.csl \
--lua-filter remove-tables-images.lua
How to automatically compile two versions of the same document, for example version without answers for the students and another version with answers for myself?
I have a small bash script to do a dual format.
function latex-ans () {
n=$(basename $1 .tex) # strip .tex in filename foo.tex -> foo
ln -s $n.tex $n-ans.tex # create a soft link (for instance foo-ans.tex -> foo.tex)
pdflatex '\def\withanswer{1} \input{'$n-ans'}' && pdflatex $n
% first format the version with answers and then the normal version
rm $n-ans.tex $n-ans.log
% remove useless files
}
If I have a file foo.tex, this commands formats both versions of the file and generates two pdf: foo.pdf and foo-ans.pdf. Thanks to the renaming of foo.tex through the ln -s, it also keeps separate foo.aux and foo-ans.aux to preserve useful information on both versions.
At the latex level, I basically do the same and use the macro \withanswers to configure my packages.
There are several packages that allow to conditionally exclude certain parts of the document, for example the exercise package.
With TeXstudio, the following magic comment can be used to automatically compile both versions at once (including repeated compilation for cross-references, bibliographies, indices etc.):
% !TeX program = latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=% -pretex="\newcommand{\version}{noanswer}" -usepretex % | latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=%_solution -pretex="\newcommand{\version}{}" -usepretex % | txs:///view-pdf "?am)_solution.pdf"
\documentclass{article}
% setting a default value in case it is compiled without the magic comment
\ifdefined\version
\else
\def\version{noanswer}
\fi
\usepackage[\version]{exercise}
\begin{document}
\begin{Exercise}[title={Title},label=ex1]
question text
\end{Exercise}
\begin{Answer}[ref={ex1}]
solution
\end{Answer}
\end{document}
I am struggling to convince pandoc to set the language for a listing automatically when converting from extended markdown (pandoc) to latex with the --listings argument. This is the file foo.txt:
A listing follows.
~~~{.prolog}
% fooing around
foo :-
format("bar~n").
~~~~
When I use pandoc -s foo.txt -o foo.html, the code is highlighted.
When I use pandoc -s foo.txt -o foo.latex, the code is highlighted, using the custom commands inserted by pandoc in the LaTeX preamble.
When I use pandoc -s foo.txt --listings foo.latex, the code is not highlighted, as the language option to the listings environment is not set. I can work around this:
~~~{.prolog language=Prolog}
but this defeats the purpose. Am I missing something or is this functionality not supported? If it omitted on purpose, what is the reason?
I am trying to spellcheck a LaTeX document (using Word), and use OpenDetex to convert it to plain text. The command line with default parameters:
$ detex foo.tex > foo.txt
Problem: some garbage, especially bibliography ids from \citep{} and \citet{} commands stay in the text.
How can I exclude these specific tags?
The -c option only excludes \cite, but not \citep and \citet.
I tried using the -e option like:
$ detex -e citep foo.tex > foo.txt
to no avail.
The documentation is a bit vague on that:
detex [-e environment-list] [-c] [-l] [-n] [-s] [-t] [-w] [file[.tex] ]
...
-e <env-list> list of LaTeX environments to ignore\n
...
Any ideas how to make it work?
\citep and \citet are not LaTeX environments, they are commands, and as such the -e flag of detex has no effect on it. The flag -e is only for environments.
The new version of detex 2.8.2 that you can obtain here.
as long as the commands (\citep and \citet) do not start at the first character in a line -- that is a bug and will be fixed.
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.