I want to convert a Jupyter notebook to LaTeX using nbconvert. The default exporting behavior is to convert Jupyter hypertext links
[a link](http://some.website.com)
to a LaTeX string that can be rendered as a link in a PDF document:
\href{http://some.website.com}{a link}
I would like to change this behavior, so that links are rendered instead as footnotes:
a link\footnote{http://some.website.com}
What do I have to modify to do this? I've looked at the documentation for nbconvert but haven't been able to figure it out. Is it possible to do this within a .tplx template file? I've looked at the standard template files and don't see anything defining the URL behavior, so I'm guessing it's handled by pandoc somehow, but I'm confused about where I need to change something.
You can use LaTeX to redefine the \href command. Put the following in your template or using header-includes:
\let\oldhref=\href
\renewcommand{\href}[2]{\footnote{\oldhref{#1}{#2}}}
Alternatively, you could write a pandoc filter to rewrite the actual output to a RawInline "latex" "\footnote"...
Related
I have been writing a document in bookdown where within the *.Rmd file I call a figure by using the following syntax
\#ref(fig:MyFigureName)
This differs slightly from the notation that you would use in a normal RMarkdown file exporting to latex which would be
\ref{fig:MyFigureName}
The issue I am running into is that when I write something in bookdown the function calling the Figure is not being highlighted properly (see image below).
I have imported my own rsTheme (which is from my understanding, basically a .css file) but I don't see an option to add keywords to highlight.
But I would like for the entire function to be colored differently from the inline text (Photoshop version of desired output shown below)
Does anyone know how I would edit my *rsTheme file in order to accomplish this?
Thanks!
rmarkdown, following {xe|lua}latex, allows to specify fonts for main text, sans-serif text, monspaced text (most notably code chunks !) and math fonts in the YAML header. At least for PDF rendering via xetex, this works.
However, I found no (documented) way to pass options to the underlying setxxxfont \LaTeX command. For example, the YAML fragment :
```
monofont: Inconsolata
```
generates the following \LaTeX fragment :
\setmonofont[Mapping=tex-ansi]{Inconsolata}
I have two questions with this:
why is the Mapping=tex-ansi added ? And how to control it ? (I'm working in UTF8...).
How could I set additional arguments for the font options i.e. \setmonofont[Scale=0.91]{TeX Gyre Cursor}?
The R Markdown book and the Pandoc's User's Guide did not reveal anything pertinent.
Background:
When R Markdown converts the knitted code to the output format (PDF), a pandoc template is used. The template is stored within the package, and any variables which get replaced by the YAML variables are contained in the $$ Notation
1. Encoding
The Mapping=tex-ansi is added to the code as a workaround an issue as reported on GitHub. Therefore I would be cautious of deleting this for potential side effects.
If you do indeed wish to change this code, you will have to make a copy of the LaTeX template file used to convert the document. You can find the default template here. See here for some more information on providing custom templates.
2. Additional Font Options
You can use the monofontoptions YAML argument to add additional arguments to the font options.
Documentation of the variables which can be parsed by the LaTeX output are available in the pandoc documentation
I'm using an R Notebook and I'd like my plots to automatically save to disk when the code is run, as well as display inline.
knitr: include figures in report *and* output figures to separate files addresses this for R Markdown but the solution given doesn't work for an R Notebook. Is there a similar option for R Notebooks?
Try setting the knitr fig.path option:
knitr::opts_chunk$set(fig.path = "path/to/figures/")
Where path/to/figures/ is the path to a subdirectory where your figures will be saved. The trailing slash is necessary. This should be a relative path, either relative to the RNotebook file or to the project directory. See here::here() for a handy way to locate the project directory.
This will put each figure into that directory; figure names will be based on the chunk name (so name your chunks!)
This is what eventually worked for me (see #TCZhang 's answer to my question here):
In addition to setting the knitr chunk fig.path="figures/" option suggested by #DonJ, try setting output: html_document, or just press the dropdown next to the Preview [Notebook] button at the top and press Knit to HTML. I think the reason this isn't working is that your output is set to output: html_notebook.
I don't know why this doesn't work specifically when the doc is in R Notebook format. I would also prefer if this worked for output: html_notebook, so it might be an issue we need to open with RStudio or knitr.
When converting markdown to html the default is (I think) to convert an image file into a string and embed it into the html file. When running knit on an rhtml file this is not the case though. Here a separate figure folder is generated, which is of course a sensible default setting.
But if I want my images to be embedded, is there a way to achieve this using rthml and knitr as well? I can't find any options where to declare this.
Thanks, Mark
Alright, I figured out myself. Seems to work just the same as with .Rmd files, by simply passing the string "base64_images"to the options argument in knit2html.
knit2html("foo.Rhtml", options=c("base64_images"))
I'm writing a major report, and have two PDF files I'd like to include as appendices. The report is written using ReStructuredText, and rst2pdf will be used to convert it.
Does docutils or rst2pdf have any functionality for external files as appendices?
Docutils has the raw directive for passing data through to the final output untouched. In the documentation they demonstrate this for the LaTeX and HTML outputs. rst2pdf seems to support this directive: in the manual they use the raw directive to include some text/commands in the final PDF (see the section headed Raw Directive) but they do not demonstrate using this directive for including external PDF files.
If rst2pdf does support this feature, you should just be able to use:
.. raw:: pdf
:file: your_pdf_file.pdf
:encoding: the encoding of the PDF file, if different from the
reStructuredText document's encoding.
I have just had a go at doing this (if in doubt, give it a go) and I get a number of UnicodeDecodeErrors, so the feature seems to be supported but I can't get it to work.
You could embed PDFs as images, but that makes no sense for appendixes.
If you only have those files as PDF, you can add them using a PDF manipulation tool, but those usually break page numbering or links or some other piece of the PDFs.
In the end, I couldn't fix this problem directly. I converted the ReStructuredText file to Latex, and included the appendices there.