RStudio on Windows not using XeLaTeX - rstudio

I'm using RStudio 0.99.896 on Windows 10.
I am trying to use knitr to convert a RMarkdown file to PDF using the XeLaTex engine.
I have set the Global Options and the Project Options in RStudio to build with XeLaTex
You can see that I have selected XeLaTeX in the global options (see pic)
and I have also selected it in the project options (see pic)
Here is a minimal reproducible example of a markdown file that fails when I call knitr:
---
header-includes:
- \usepackage{fontspec}
output:
pdf_document
---
```{r}
data(mtcars)
```
When I call Knit PDF on the file above, I get the following output:
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS
sample1.utf8.md --to latex --from
markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
--output sample1.pdf --template "C:\Users\xxxx\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default-1.14.tex"
--highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" output file:
sample1.knit.md
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ! Fatal fontspec
error: "cannot-use-pdftex" ! ! The fontspec package requires either
XeTeX or LuaTeX to function. ! ! You must change your typesetting
engine to, e.g., "xelatex" or "lualatex" ! instead of plain "latex" or
"pdflatex".
You can see in the bold part of the output shown above that RStudio is still calling pdflatex instead of xelatex.
I'm not sure why that is. Any thoughts on a setting that I have missed?

I had this problem too.
Try this:
output:
pdf_document:
latex_engine: xelatex
In addition to everything else you did. This fixed it for me!

Related

Sphinx: Bibtex bibliography with EPUB generator

I'm trying to utilize Sphinx to build three fold output - HTML, Latex, and EPUB. The bibliography is standard bibtex. With HTML and Latex it works perfectly well. However, EPUB generator:
sphinx-build -b epub -D extensions=sphinx.ext.imgmath -D imgmath_embed=True . epub/
produces the following errors:
WARNING: unknown directive or role name: cite:t
3-poplavni.rst:170: ERROR: Unknown interpreted text role "cite:t".
literatura.rst:7: ERROR: Unknown directive type "bibliography".
.. bibliography::
Any advice?
EPUB generator should work well with Bibtex as Latex and HTML generators do.
Perfect! As you suggested:
sphinx-build -b epub -D extensions=sphinx.ext.imgmath,sphinxcontrib.bibtex -D imgmath_embed=True . epub/
works like a charm.

Pandoc citeproc bibliography entries sorting follows the order of entries in bib file

When I convert the markdown file to pdf the order of references in the bibliography is the same as in the .bib file. As a result, the references in the text appear in the wrong order. As a result, I can have in the text sentences like ... reported in [2] after [1] ... while I would like the references to be sorted in the bibliography as they appear in the text, as it would be using unsrt.bib.
The question is: how do I achieve sorting of entries in the bibliography section in order of their appearance in the text?
MWE, compiled using pandoc -C -f markdown testing.md -o testing.pdf
testing.md:
---
bibliography: test.bib
csl: aps.csl
---
The first reference [#second_title_2015]
The second reference [#author_title_2014]
test.bib
#article{author_title_2014,
title = {The title},
author = {Author, A. B. and Other, C. D.},
year = {2014},
}
#article{second_title_2015,
title = {The other title},
author = {Second, T. A. and First, F. G.},
year = {2015},
}
The output
Changing the order of #article's in test.bib results in the desired output: The first reference [1] the second reference [2].
I am using the aps.csl taken from zotero style repository:
https://www.zotero.org/styles/american-physics-society?source=1
cause of the problem:
I had an outdated pandoc installed by conda (pandoc is a prerequisite for some important packages I needed), and this version took precedence over the default arch installation because of conda's executables dir being in $PATH before /bin/.
Did you use outdated pandoc? I tested your code with pandoc 2.13, which produced the correct output. You can get the latest release here.
pandoc --version
pandoc 2.13
Compiled with pandoc-types 1.22, texmath 0.12.2, skylighting 0.10.5,
citeproc 0.3.0.9, ipynb 0.1.0.1
pandoc -C -f markdown testing.md -o testing.pdf

How can I specify pandoc's markdown extensions using a YAML block?

Background
Pandoc's markdown lets you specify extensions for how you would like your markdown to be handled:
Markdown syntax extensions can be individually enabled or disabled by appending +EXTENSION or -EXTENSION to the format name. So, for example, markdown_strict+footnotes+definition_lists is strict markdown with footnotes and definition lists enabled, and markdown-pipe_tables+hard_line_breaks is pandoc’s markdown without pipe tables and with hard line breaks.
My specific question
For a given pandoc conversion where, say, I use grid tables in my source:
pandoc myReport.md --from markdown+pipe_tables --to latex -o myReport.pdf
How can I write a pandoc YAML block to accomplish the same thing (specifying that my source contains grid tables?)
A generalized form of my question
How can I turn extensions on and off using pandoc YAML?
Stack Overflow Questions that I don't think completely answer my question
Can I set command line arguments using the YAML metadata - This one deals with how to specify output options, but I'm trying to tell pandoc about the structure of my input
What can I control with YAML header options in pandoc? - Answerers mention pandoc's templates, but neither the latex output template nor the markdown template indicate any sort of option for grid_tables. So, it's not clear to me from these answers how knowing about the templates will help me figure out how to structure my YAML.
There may also not be a way to do this
It's always possible that pandoc isn't designed to let you specify those extensions in the YAML. Although, I'm hoping it is.
You can use Markdown Variants to do this in an Rmarkdown document. Essentially, you enter your extensions into a variant option in the YAML header block at the start of the your .Rmd file.
For example, to use grid tables, you have something like this in your YAML header block:
---
title: "Habits"
author: John Doe
date: March 22, 2005
output: md_document
variant: markdown+grid_tables
---
Then you can compile to a PDF directly in pandoc by typing in your command line something like:
pandoc yourfile.md -o yourfile.pdf
For more information on markdown variants in RStudio: http://rmarkdown.rstudio.com/markdown_document_format.html#markdown_variants
For more information on Pandoc extensions in markdown/Rmarkdown in RStudio:
http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html#pandoc_markdown
You can specify pandoc markdown extension in the yaml header using md_extension argument included in each output format.
---
title: "Your title"
output:
pdf_document:
md_extensions: +grid_tables
---
This will activate the extension. See Rmarkdown Definitive Guide for details.
Outside Rmarkdown scope, you can use Pandocomatic to it, or Paru for Ruby.
---
title: My first pandocomatic-converted document
pandocomatic_:
pandoc:
from: markdown+footnotes
to: html
...
As Merchako noted, the accepted answer is specific to rmarkdown. In, for instance, Atom md_extensions: does not work.
A more general approach would be to put the extensions in the command line options. This example works fine:
----
title: "Word document with emojis"
author: me
date: June 9, 2021
output:
word_document:
pandoc_args: ["--standalone", "--from=markdown+emoji"]
----
For people stumbling across this in or after 2021, this can be done without Rmarkdown. You can specify a YAML "defaults" file, which basically includes anything you could want to configure.
In order to do what OP wanted, all you'd need to do is
from: markdown+pipe_tables
in the defaults file, then pass it when you compile.
You can also specify the input and output files, so you can end up with the very minimal command
pandoc --defaults=defaults.yaml
and have it handle the rest for you. See https://pandoc.org/MANUAL.html#extensions for more.

Pandoc: use variables in custom latex preamble

I have the file test.md which contains:
---
footertext: some text for the footer
headertext: this is in the header
---
here is the text body.
And the file format.tex which contains:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{$headertext$}
\fancyfoot[L]{$footertext$}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}
I run the command:
pandoc -H format.tex test.md -o test.pdf
You can see what I want to do. I am trying to get the text "this is in the header" to show up in the header, but it does not, it only shows the string "headertext" (same problem for footer).
What am I doing wrong?
Edit: OK, I think I understand. Apparently variables are only available in templates, not in included begin or end code blocks (like I am using), or in the md itself. So new question: Why is this? It is unintuitive, inconvenient, and poorly documented.
You can easily modify a pandoc template. Access the default template with
pandoc -D latex > new_template.latex
Paste the content of your format.tex in the preamble. You should use $if$ to check if the variable exists before using it if you want to use this template for more than one document :
\usepackage{fancyhdr}
\pagestyle{fancy}
$if(headertext)$\fancyhead[L]{$headertext$}$endif$
$if(footertext)$\fancyfoot[L]{$footertext$}$endif$
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}
Then compile with :
pandoc test.md -o test.pdf --template=new_template.latex

How do I add the -shell-escape option in TexShop

I am using the minted.sty package and it is requiring that I use the -shell-escape option during latex/xelatex compile. I can do that over the console/terminal. However, I wish to add this option into TexShop. I am prior user of WinEdit on Windows but have recently switched to Mac and TexShop, so don't know how to do it?
Here is the console output:
Package ifplatform Warning:
shell escape is disabled, so I can only detect \ifwindows.
))
! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.54 \makeatletter
in case you are still looking for an answer:
Go to the Preferences
Go to Tab "Engine"
Go to Field "pdfTeX"
In the LaTeX Input Field add --shell-escape at the end.
before: pdflatex --file-line-error --synctex=1
after: pdflatex --file-line-error --synctex=1 --shell-escape

Resources