Define Latex packages in reST file - latex

We used Docutils to produce reST document, and then make a TeX file via rst2latex.
In the rst file, we have added a lot of LaTeX code like:
.. raw:: latex
~\\
\rule{\textwidth}{1pt}
~\\
But I do not know where to add packages like \usepackage{tabulary}.
If I add it in the rst file like I've shown above, even in the very beginning, this \usepackage line is automatically added after \begin{document} in the tex output file. This obviously generates an error.
Any idea where can I add \usepackage commands in reST?

You can use the LaTeX preamble (after Docutils 0.7) by
rst2latex foo.rst foo.tex --latex-preamble="\usepackage{tabulary}"
which will generate the following in foo.html
%%% Custom LaTeX preamble
\usepackage{tabulary}
Alternatively, a custom stylesheet can be provided by
rst2latex foo.rst foo.tex --stylesheet=preamble.tex
which will generate
%%% User specified packages and stylesheets
\input{preamble.tex}
in the right place.

Related

Latex: setting another directory for bibliography of natbib package (windows)

How to declare a different directory than the working folder with the natbib package using Tex Studio (Windows)? There is a directory for all my bibliographies (BiblioX.bib), and I use multiple per document. The bibliography path is : C:\Users\User\Dropbox\PDF\Bib ,and the working folder is : C:\Users\User\Dropbox\R&D\Project\Article\Work_Article .
The following code works:
\documentclass[12pt, a4paper]{article}
%Bibliography
\usepackage{natbib}
\bibliographystyle{newapa}
\begin{document}
\bibliography{../../../../../PDF/Bib/Biblio1,../../../../../PDF/Bib/Biblio2}
\end{document}
The goal would be to be able to use instead:
\bibliography{Biblio1,Biblio2}
Therefore declare a directory that Natbib would recognize : C:\Users\User\Dropbox\PDF\Bib
I thought about using a variable (or a new command):
\def \BibPath {C:/Users/User/Dropbox/PDF/Bib}
\bibliography{\BibPath/Biblio1,\BibPath/Biblio2}
But it does not work with the Natbib drop menu allowing to select the reference when writing \cite{ in Tex Studio. Is there a way to change the default of where Natbib/Tex Studio looks for bibliography?
Thanks!

adding latex packages to doxygen can not work

I want to add some graphics to my doxygen generated output. For that I need to add some more packages:
\usepackage{tikz}
\usepackage{tikz-timing}
\usetikzlibrary{mindmap}
\usetikzlibrary{arrows,shadows}
The first two lines can be added to the Doxyfile with
EXTRA_PACKAGES = {tikz} \
{tikz-qtree}
But the 2 other ones are not.
Is there a chance to add a .tex file into the generated output files before pdflatex starts?
Adding
LATEX_EXTRA_STYLESHEET = packages.tex
will not work. It used my file but the output is broken. Seems that the packages are loaded at the wrong place or time.
The third thing i tried was writing a header file with
doxygen -w latex ....
This works and changing the header.tex file is ok, but this ends up in always in generating the header, patching the header, run doxygen again with own header. This is very stupid!
Any idea?
The EXTRA_PACKAGES option is equivalent to the \usepackage tag in Latex. This of course doesn't work for the \usetikzlibrary tags.
You can add your modified Latex header using the tag LATEX_HEADER in the Doxyfile, e.g.:
LATEX_HEADER = ./templates/latex/YourCustomHeader.tex
Then Doxygen pulls this Latex header file when generating the documentation. In this file you can add the used packages and libraries.
By the way: The custom stylesheet isn't used before you run the make.bat script, so it is sufficient if you copy the modified 'doxygen.sty' file to the output folder after Doxygen generated the Latex files, but before you run the 'make.bat' script to generate the PDF file. I do this by a script which first calls doxygen then copies the necessary files to the output folder and finally calls the 'make.bat' script...

Set double spacing and line numbers when converting from Markdown to PDF with pandoc

I am using markdown & pandoc for scientific writing, I know I can change margins of the final pdf using
Set margin size when converting from Markdown to PDF with pandoc
but very often the journals require double lines and line numbers in submitted manuscripts, the question is how to change these, I don't know much about LaTex so I am lost in that jungle.
Thanks!
In more recent version of Pandoc, you can use a YAML header and include a bunch of metadata in that, instead of using options on the command line. So, for instance, you can put this at the top of your .md file:
---
title: The Document Title
author:
- Your Name
- Co Author
date: \today{}
geometry: margin=2cm
header-includes:
- \usepackage{setspace}
- \doublespacing
- \usepackage{lineno}
- \linenumbers
---
Document Text
and pandoc will read those options and apply them automatically.
There is maybe an easy way: generate a file with the packages we need
\usepackage{setspace}
\doublespacing
\usepackage[vmargin=1in,hmargin=1in]{geometry}
\usepackage{lineno}
\linenumbers
I named it options.sty. And use the -H FILE option that includes the content of the FILE at the end of the preamble. (as used in https://github.com/karthikram/smb_git)
pandoc -H options.sty --bibliography mypaper.bib mypaper.md -o mypaper.pdf
The advantage is that we don't need to edit the template. To add linenumbers, change margins, and set spacing it works.
You'll need to use a custom LaTeX template. First, use pandoc to create a copy of the default template:
pandoc -D latex > mytemplate.latex
Now edit this template. Somewhere in the preamble (between \documentclass{...} and \begin{document}), insert the lines
\usepackage{setspace}
\doublespacing
Then, to use your custom template:
pandoc --template mytemplate.latex mypaper.txt -o mypaper.tex

Can I write cls files in LaTeX instead of TeX?

I have some initialization code in a XeLaTeX file which I would like to put into a separate file so that I can reuse it in future texts. What is the fastest way to convert my XeLaTeX code to a LaTeX class file?
You can put your preamble code into a .cls file and then use \documentclass{mydocstyle} to load it. Your .cls file will look like this:
% Declare that this document class file requires at least LaTeX version 2e.
\NeedsTeXFormat{LaTeX2e}
% Provide the name of your document class, the date it was last updated, and a comment about what it's used for
\ProvidesClass{mydocstyle}[2010/09/13 Bluetulip's custom LaTeX document style]
% We'll pass any document class options along to the underlying class
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{article}% or book or whatever
}
% Now we'll execute any options passed in
\ProcessOptions\relax
% Instead of defining each and every little detail required to create a new document class,
% you can base your class on an existing document class.
\LoadClass{article}% or book or whatever you class is closest to
% Now paste your code from the preamble here.
% Replace \usepackage with \RequirePackage. (The syntax for both commands is the same.)
% Finally, we'll use \endinput to indicate that LaTeX can stop reading this file. LaTeX will ignore anything after this line.
\endinput
Note that document class files can get much more complicated (if you want to include options like \documentclass[option]{mydocstyle}, etc.), but this basic format should get you started.
Save your file as mydocstyle.cls and put it in the current directory with your .tex file.
You can also take a look at the LaTeX2e for class and package writers guide. It'll walk you through this in more detail.

LaTeX help with href

I am trying to create a hyperlink using LaTeX. When I use the command pdflatex to compile the file, I get an error.
The relevant lines of the document are:
\documentclass[12pt]{article}
\usepackage{hyperref}
\begin{document}
...
\href{http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html}{gprof}
pdflatex created a file called missfont.log, which contains this:
mktextfm pzdr
What am I doing wrong?
Do you have the pzdr font installed? If you're on Debian or Ubuntu, try installing the texlive-fonts-recommended package.
Does the hyperref package purport to make hyperlinks to arbitrary web pages? I thought it was just for intra-document links (which it does automatically). I would do
\usepackage{url}
and
\url{http://foo.com}
to format a URL in your document.
ADDED: Thanks Will, I didn't know that about href. But if you're creating a document that's mainly targeting paper as the intended medium, I think the url package for formatting URLs is the way to go. But if you think the href package subsumes the url package, I'd love to be set straight on that.

Resources