Sphinx starts chapter numbering from 0 in LaTeX output - latex

I'm generating a PDF document With Sphinx using latex.
======================
RX-loader instructions
======================
Program
=======
However this generates
0.1 RX-loader instructions
0.1.1 Program
How do I make the numbering start with 1?
Edit:
My index.rst looks like this
#######################
RX-loader documentation
#######################
.. toctree::
:maxdepth: 2
rx-loader
My problem seems to be that the numbering takes "RX-loader documentation" as chapter 0 and always writes the chapters the section numbers.

The following might be a dirty trick but it results in the desired pdf behaviour on Sphinx 1.6.7 (In html the first line must be removed):
Filler text
======================
RX-loader instructions
======================
Program 1
---------
Program 2
---------
Output:

Related

Pandoc Column Width for Twocolumn not working

I cannot get column width recognized. It is as if it is just ignored and each column is exactly 50% of the available space. Additionally the example implies I can tell it when I want the 2nd column to start but that is also ignored.
The following is from the Pandoc manual column example, but when I compile it via pandoc they are just each 50% width not what is specified. The frontmatter in my example was not provided in their example but its what I figure it must be to get the columns working. I've tried this with and without the frontmatter.
I'm using ubuntu 18.04 within WSL2 and pandoc version:
pandoc 2.17.1.1 Compiled with pandoc-types 1.22.1, texmath 0.12.4,
skylighting 0.12.2, citeproc 0.6.0.1, ipynb 0.2
I'm using these command line entry for compiling it: (I've also tried pdflatex engine as well)
pandoc mat_doc.md --pdf-engine=xelatex -o mat_doc.pdf
Here is the file:
---
output: pdf_document
classoption: twocolumn
---
:::::::::::::: {.columns}
::: {.column width="60%"}
contents
:::
::: {.column width="40%"}
contents
:::
::::::::::::::
How do I get different sized columns? Why does this not work per their manual? Thx!
The beamer columns you are trying to use, are something special in the beamer class and don't work with normal classes.
However under the hood, these columns are just glorified minipages - and these you can use in normal latex classes.
---
output: pdf_document
---
\noindent\begin{minipage}{.6\textwidth}
test
\end{minipage}
\begin{minipage}{.4\textwidth}
test
\end{minipage}

How to convert Rmarkdown file to working latex file

I have written a manuscript I would like to submit to a journal in Rmarkdown. The journal accepts word and latex files, so I am looking for a way to generate a working .tex file out of my .Rmd file.
I have read some posts that allude to this being possible (e.g., How to generate LaTeX file without preamble in R markdown?) and this is getting me some of the way, but I am still having problems.
For example, using the method mentioned in the post above, I can convert a test .Rmd into something with a .tex filetype. This is the test Rmarkdown (just the usual template for new files):
---
title: "Test document"
author: "Me"
date: "23 7 2020"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
This compiles fine to PDF as it should. Then, in the console I run:
knitr::knit("test.Rmd")
to get a markdown file test.md in my working directory, and then I can apparently convert this .md file to .tex with
rmarkdown::pandoc_convert("test.md", to = "latex", output = "test.tex")
This produces a .tex file that, when I double click on it, pops up a PDF view of the file that looks fine. Taking a look at the file though, it is incomplete or at least unfamiliar to me:
\hypertarget{r-markdown}{%
\subsection{R Markdown}\label{r-markdown}}
This is an R Markdown document. Markdown is a simple formatting syntax
for authoring HTML, PDF, and MS Word documents. For more details on
using R Markdown see \url{http://rmarkdown.rstudio.com}.
When you click the \textbf{Knit} button a document will be generated
that includes both content as well as the output of any embedded R code
chunks within the document. You can embed an R code chunk like this:
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{summary}\NormalTok{(cars)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
\end{verbatim}
\hypertarget{including-plots}{%
\subsection{Including Plots}\label{including-plots}}
You can also embed plots, for example:
\begin{figure}
\centering
\includegraphics{figure/pressure-1.png}
\caption{plot of chunk pressure}
\end{figure}
Note that the \texttt{echo\ =\ FALSE} parameter was added to the code
chunk to prevent printing of the R code that generated the plot.
As far as I can tell, it is missing the preamble, \begin{document}, \end{document}, and I have no idea what is going on with hypertarget bit of the section headers. Unsurprisingly, it does not "re-compile" when I hit run in MiKTeX. The verbatim bits for the code chunks look to be what I'm after, though.
So, is there a way to generate a .tex file that compiles out of an .Rmd file? Or will I have to manually write the preamble and all that? If the answer to my problem is "read up pandoc", then fair enough, I will have to bite the bullet and finally have a look at it. But I find it hard to imagine that there is no good (easy) way to prepare submittable manuscripts in Rmarkdown.
Pandoc generates LaTeX snippets by default, i.e., not a full document. This can be changed by calling pandoc with the --standalone option:
rmarkdown::pandoc_convert(
"test.md",
to = "latex",
output = "out.tex",
options = "--standalone"
)
You can let R do the work and shorten your commands to
render("test.Rmd", output_format = "latex_document")
A project of interest might be rticles.

citations in Pandoc footnotes rendered as numerals

I am getting a weird result when I convert markdown to PDF using Pandoc. This is for academic writing with footnotes generated via citeproc; a bibtex library generated by Zotero; and a Chicago csl file. Most of the footnotes are fine, but sometimes where I should see a book or article I just get a numeral.
When I write the following in Markdown
^[#melvilleMobyDick, 155]
I want a footnote that says
Herman Melville, Moby-Dick, p. 155
but I get
1, p. 155
The problem seems to be in the transition from markdown to LaTeX; the latter output is:
\footnote{1, 155}
My shell command is:
$ pandoc article.md -o article.latex --filter=pandoc-citeproc
And I am using this YAML header:
title: Essay
bibliography: My_Library.bib
csl: chicago_fullnote_ibid.csl
Many thanks for your help.
You're using chicago_fullnote_ibid.csl, which styles citations as footnotes. So just do [#melvilleMobyDick, 155] instead of ^[#melvilleMobyDick, 155] and it will turn into a footnote.

Using bib2gls with rmarkdown fails to render glossary

I'd like to use the bib2gls latex package in my rmarkdown document to insert a list of acronyms from a .bib file when I knit to a pdf document.
Doesn't work:
Using a .bib file to store my acronyms. Example:
abbreviations.bib file:
#abbreviation{ecoli,
short={E.~coli},
long={Escherichia coli}
}
#abbreviation{raustralis ,
short ={R.~ australis},
long={Rickettsia australis}
}
preamble.tex
% fixes problem with glossaries causing mathspec
% to return an error asking for amsmath to be loaded first
\makeatletter
\let\RequirePackage\original#RequirePackage
\let\usepackage\RequirePackage
\makeatother
% using bib2gls
\usepackage[record,abbreviations,style=index]{glossaries-extra}
\setabbreviationstyle{long-short}
\GlsXtrLoadResources[src={abbreviations},selection={all}]
rmarkdown file:
---
output:
pdf_document:
latex_engine: xelatex
includes:
in_header: preamble.tex
title: "mwe"
---
## R Markdown
This is the first instance \gls{ecoli}, \gls{raustralis}. This is the second instance: \gls{ecoli}, \gls{raustralis}.
\printunsrtglossary[title={Abbreviations},type=abbreviations]
The output when I knit the rmarkdown documents looks like:
What works:
Removing \GlsXtrLoadResources[src={abbreviations},selection={all}] and adding my entries into the preamble.
% using bib2gls
\usepackage[abbreviations,style=index]{glossaries-extra}
\setabbreviationstyle{long-short}
\newabbreviation{ecoli}{E.~coli}{Escherichia coli}
\newabbreviation{raustralis}{R.~australis}{Rickettsia australis}
I'd like to use the separate .bib file in the first approach if possible. Unless there is a better approach to do this in R. Session info is below:
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
The Problem is that bib2gls requires an additional program to be run, which extracts the glossary entries from the bib file, but rmarkdown does not know about that. In general, if you want to do something more complicated on the LaTeX side, there is a good chance that latexmk already knows how to do that. I am not sure if this is here the case, c.f. https://tex.stackexchange.com/questions/400325/latexmkrc-for-bib2gls. However, you can give it a try using
```{r echo=FALSE}
Sys.setenv(RSTUDIO_PDFLATEX = "latexmk")
```

Pandoc-generated PDF: Change list numbering style

What is the way to change the style of numbers in ordered lists generated by Pandoc?
For the following Markdown input
1. One
2. Two
1. Sub 1
2. Sub 2
Pandoc generates the following Latex output
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\itemsep1pt\parskip0pt\parsep0pt
\item
One
\item
Two
\begin{enumerate}
\def\labelenumii{\arabic{enumii}.}
\itemsep1pt\parskip0pt\parsep0pt
\item
Sub 1
\item
Sub 2
\end{enumerate}
\end{enumerate}
This results in the following PDF output:
1. One
2. Two
1. Sub 1
2. Sub 2
While I'm trying to achieve
1. One
2. Two
2.1. Sub 1
2.2. Sub 2
I tried to redefine style of numbering in the default template with these commands
\renewcommand{\labelenumii}{\theenumii}
\renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}
but as Pandoc generates explicit definition for labelenumii this solution does not work.
Update
It turns out that the problem could be resolved by using #. notation instead of 1. one. For whatever reason Pandoc skips styling only for lists defined this way and interprets the standard Markdown notation as an instruction to style list with plain numbers. Hopefully in future versions it will be a bit more flexible and will add the support for nested numbers in lists.
edit
This function of the latex writer that adds the \def\labelenumi{} part checks for numstyle == DefaultStyle && numdelim == DefaultDelim. As #oleg found out, this might be accomplished with #. list markers, so that this should work:
---
header-includes:
- \renewcommand{\labelenumii}{\theenumii}
- \renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}
---
#. One
#. Two
#. Sub 1
#. Sub 2
There are two feature requests asking for a native markdown solution on the issue tracker (336 and 1627), as well as a discussion on the mailing list.
pre-edit answer
Of course, you could always compile to latex, postprocess the file to remove those \def\labelenumi{} lines, and then compile the latex file. Here is an example that works with the standard latex template.
test.md
---
header-includes:
- \renewcommand{\labelenumii}{\theenumii}
- \renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}
---
1. One
2. Two
1. Sub 1
2. Sub 2
commands:
pandoc test.md -t latex -s | sed '/\\def\\labelenumi/d' > test.tex
xelatex test.tex
But all the lists of your document will be affected, and you need to write the latex compilation commands yourself.

Resources