LaTeX create ONLY table of contents - latex

I have some documents scanned as pdf, and since I want to hand them in to my university combined as one document, I want to attach a table of contents to make the reader aware of the fact, that there are several documents inside this pdf. So, since I already have the documents and I am not producing them in Latex anymore, I only want to create the table of contents in Latex. Usually, Latex pulls its information for the toc out of the document it won't have this time. So, is there manual way of creating a table of contents, where I can type in myself, which section exists and what page it is on?
Thank you all in advance
and have a nice weekend!
PS: I double checked if that topic was already dealt with, but I didn't find anything.

So, apparently the answer lies in the .toc file which is auto generated when compiling. This document contains commands with the pattern
\contentsline {section}{\numberline {<number of enumeration>}\ignorespaces <heading>}{<pagenumber>}%
this comment also works when used after the \tableofcontents command.

Related

Tables in R-markdown not shown in Moodle - exams2moodle

I have a serious problem with rendering tables in Moodle once I upload the Moodle XML file generated by R-exams package to Moodle. I am using exercise files in .Rmd format handed to me from a previous professor's assistant. These .Rmd files contain lots of tables using Latex language. Once I upload the Moodle XML file, all of these tables are simply missing. I have tried to look up a solution, but could not find anything helpful on this.
Interestingly, these tables are rendered properly into PDF when using "exams2pdf" command in R-studio. However, when using "exams2moodle", these tables are simply not shown in Moodle.
I am showing an example of the table in one of these .Rmd files below:
I would appreciate if anyone could provide any guidance, as I got really stuck with this issue.
TL;DR: The problem is that you mix an exercise in Markdown format with LaTeX content. This only works if the rendering goes via LaTeX (see below for details). Instead you could convert your question from R/Markdown (.Rmd) to R/LaTeX (.Rnw) - or convert the formatting of the table from LaTeX to Markdown. Both would be feasible in this case. If you need help with this, please share (a link to) the code for the exercise and not just a screenshot of parts of it.
Hint: If you're using at least version 2.4-0 of exams, exams2moodle() gained an argument table where you can set a class for formatting the table a bit more nicely, e.g., table = "table_shade" or "table_rule" or "table_grid".
Details: You have a question in R/Markdown format which contains a table in LaTeX format. When you use exams2pdf() this works because rendering works in the following steps:
knit R/Markdown to Markdown (preserving the LaTeX table).
Convert Markdown to LaTeX via pandoc (preserving the LaTeX table).
Render LaTeX (including the table) to PDF using texi2pdf or latexmk.
Thus, it is crucial that you do a rendering step from LaTeX to the output format. This is not the case though for exams2moodle() or other engines based on HTML output. The steps are just:
knit R/Markdown to Markdown (preserving the LaTeX table).
Convert Markdown to HTML via pandoc (which does not know how to render the LaTeX table and hence drops it).
Embed HTML in XML for Moodle.
Thus, the problem is that there is no rendering or transformation step from LaTeX in this case. The same would be true if you had R/Markdown exercises with HTML content. These could be rendered with exams2moodle() because the HTML would just need to be preserved - but not with exams2pdf() because the HTML would not be converted to LaTeX.

R --markdown to latex - tables do not show up

I am using Knitr in Rstudio, to generate markdown files. I display the tables via xtable package and it shows up nicely in html file. However, when I converd .md to latex via pandoc - the latex file does not contain the tables as it is supposed to be, but only the values in table without any command.
Markdown - Knitr input
In order to give a better idea, the following table provides a sample of
data rows:
```{r table, results='asis', echo=FALSE}
r = read.table("C:/aR_files/data.txt",sep=",", header=TRUE,as.is=TRUE)
r$X = NULL;
print(xtable(r), type='html')
```
Latex
In order to give a better idea, the following table provides a sample of
data rows:
Row1
Row2
Val1
Val1
I thought I may be missing a latex package, so I downloaded ctable.sty, but still I get the same output. Any ideas appreciated, thanks!
I use a very similar workflow to yours and your best bet is to abandon the often clunky xtable package and use the pander package to print your tables. You can wrap any object that you might want to display as a table in the generic pander() function. This is a wrapper for the pandoc.table() function which has several options. If you specify the option style = "XXX" you can achieve what you are asking about here. There are 4 different styles you can choose from; "multiline" (the default), "grid", "simple", or "rmarkdown". I frequently knit rmarkdown documents from within Rstudio and then convert them to Word documents using the pander package:
library(pander)
Pandoc.convert("C:/Users/BlahBlahBlah/Document.md", format="docx")
All of the 4 table styles get turned into table objects upon conversion to .docx format, but only one table style looks right in the .docx document and the .html file that results from the initial "knit". That style is "rmarkdown". You can implement this 2 ways. One would be:
```{r table, results='asis'}
pandoc.table(myTable, style = "rmarkdown")
```
I prefer to set the table style globally at the beginning of my document however, ensuring that all my tables have the same formatting and also allowing me to use the more succinct pander(x) instead of the more verbose pandoc.table(x, style = "someStyle"):
```{r table, results='asis'}
panderOptions("table.style", "rmarkdown")
pander(myTable)
```
There are some side effects of using the rmarkdown style however. Mainly, it does not support newline characters within cells, so buyer beware. I experimented with the different styles and eventually decided that I liked the default style of "multiline" because of it's flexibility with line breaks within cells, even though the .html files I generate look silly. This doesn't bother me though, as I really only use the .docx files that I convert from the .md files. I wrote a blog post about making nice tables that you might find useful. It weighs the pros and cons of several methods including xtable() and several pander() scenarios.

Enclosing multiple LaTeX documents

I am not sure if this question is suitable for superuser instead, but I'll ask anyway.
Currently I'm writing on my documentation for my final project. I must append several other LaTeX documents as enclosure. They must be mentioned in the first Table of Contents as alphabetical appendix. I tried the package subfiles, but the subsequent TOC´s are always empty exept in case of translating them alone.
Is there any other way to append multiple full documents with there own documentclass??
subfiles is a very simple package - it doesn't try to do anything other than manage the document-level macros. You will need to issue an \appendix cs before each inclusion of a subfile.
Beware of the different latex documents sharing auxiliary files: if they do this, then subfiles will basically not work - you will be better off using the pdfpages package that absz mentions.
Postscript If you want the subsidiary documents to have their own tables of contents, you have either to change their auxiliary files (at least, their .aux and .toc files), or switch to another mechanism. Maybe minitoc will fit better?
Couldn't you strip out the preamble of the other LaTeX documents and then use \include or \input depending on whether you want pagebreaks?

Is there a way to override a bibtex style file for a particular entry?

My preferred bibtex style file cites via author's initials. However, there are various texts which should be cited differently (for example, Elements Geometrie Algebrique should always be cited as [EGA]). I know how to modify this in the .bbl file that bibtex outputs, but then I have to do this for every file. Is there a way to do this from my .bib file?
My preferred bibtex style file cites via author's initials. However, there are various texts which should be cited differently...
I hope I don't get flamed for this, but your preferred bibtex style file does not serve your readers very well. Part of my job is to review papers, and a jumble of initials like [GKS] is not nearly as helpful as a full author-date citation like [Guibas, Knuth, and Sharir 1990]. For a knowledgeable reader, the authors and date often make it unneccessary to refer to the bibliography. For a naïve reader, a group of names is much easier to remember then a group of letters, especially when one or more of the names may be familiar. These issues are discussed in detail by, e.g., the Chicago Manual of Style, which explains the proper way to cite from the professional literature.
I go on at such length because I believe you are solving the wrong problem. Although I believe your readers will quickly recognize [EGA], I would hope they would also recognize (Grothendieck 1960) or (Grothendieck and Dieudonné 1967).
Can I [modify the way a work is cited] by changing my .bib file?
Not if you want to use any of the standard BibTeX styles. BibTeX uses one of the world's worst programming languages, and the standard programs are very firm about using the author or editor of a work for form the citation key. If you really want to do this, I recommend the following procedure:
Clone and modify something like the plainnat.bst file. This will enable you to create a new "bibliography style."
Create a new type of BibTeX entry which will enable you to specify the citation key using a special field (key is a popular choice).
Alter the calc.label function to do the right thing with your new type of entry. If you're lucky, changing calc.label will be enough to be sure the thing is sorted properly.
Use your nonstandard type in your .bib file and use your nonstandard \bibliographystyle{...} in all your LaTeX documents.
The gods really don't want you to do this—and neither do your coauthors...
You can modify the .bst program so that it looks for an additional field, say shown-key, and if it is set uses that rather than the usual.
If you are willing to use a different bib style there is a way pointed out by this answer. Using the abstract style, the bibtex key is used as the cite key. Then, you edit each key in the bib file anyway you want it.
A straightforward disadvantage of this approach is that you will have to edit every item in your bib file, however I believe that it is a fair price to pay for such flexibility.
I've seen other possible solutions involving natbib or biblatex, but I wanted to avoid those packages as I sometimes get compilation problems when using them.

Including full LaTeX documents within others

I'm currently finishing off my dissertation, and would like to be able to include some documents within my LaTeX document.
The files I'd like to include are weekly reports done in LaTeX to my supervisor. Obviously all documents are page numbered seperately.
I would like them to be included in the final document.
I could concatenate all the final PDFs using GhostScript or some other tool, but I would like to have consistent numbering throughout the document.
I have tried including the LaTeX from each document in the main document, but the preamble etc causes problems and the small title I have in each report takes a whole page...
In summary, I'm looking for a way of including a number of 1 or 2 page self-complete LaTeX files in a large report, keeping their original layouts, but changing the page numbering.
For a possible solution of \input-ing the original LaTeX files while skipping their preamble, the newclude package might help.
Otherwise, you can use pdfpages for inserting pre-existing PDFs into your dissertation. I seem to recall that it has a feature of "suppressing" the original page numbers by covering them up with white boxes.
The suggestion from #Will Robertson works great. I'd just like to add an example for all lazy people:
\usepackage{pdfpages}
...
% Insert _all_ pages from some_pdf.pdf:
\includepdf[pages=-]{some_pdf} % the .pdf extension may be omitted
From the documentation of the package:
To include a specific range of pages, you could do pages={4-9}. If start is omitted, it defaults to the first page, if end is omitted, it defaults to the last page.
To include it in landscape mode, do landscape=true
Maintaining the original formatting per document will be difficult if they're using different formats. For example, concatenating different document classes will be near impossible.
I would suggest you go with the GhostScript solution with a slight twist. Latex allows you to set the starting page number using \setcounter{page}{13} for example. If you can find an application that can count the pages of a PDF document (pdfinfo in the pdfjam Ubuntu package is one example), then you can do the following:
Compile the next document to PDF
Concatenate the latest PDF with the current full PDF
Find the page count of the full PDF
Use sed to pluck in a \setcounter{page}{N} command into the next latex file
Go back to the beginning
If you need to do any other processing, again use sed. You should (assuming you fix the infinite loop in the above algorithm ;-) ) end up with a final PDF document with all original PDFs concatenated and continuous line numbers.
Have a look a the combine package, which seems to be exactly what you're searching for.
Since it merges documents at the source level, I guess the page numbers will be correct.

Resources