sphinx customization of latexpdf output? - latex

Just curious if anyone knows how to customize the sphinx output when using the latexpdf target? I've seen lots of custom stuff for html output, but cant seem to find any example of custom pdf output.
Specifically, I'd be interested in customizing the title page, headers, footers, and possibly adding a few pages of front matter before the contents.
Has anyone seen any examples of this kind of customization, or do people pretty much just use the "stock" sphinx output when generating pdfs? Thanks!

Yes i think better or clearer documentation for latex styling would be nice and
some examples.
Here is a question on the sphinx mailing list, which is about about using packages.
sphinx has its own latex documentclass in a file called sphinxmanual.cls or
sphinxhowto.cls, if i remember correctly its a report documentclass that is used as base.
then there is 2 style files, which are the packages, it is those files contents
that are called on when you write \usepackage{mylatexstilefile}
Question about using latex packages
http://groups.google.com/group/sphinx-dev/browse_thread/thread/890dab5e53fff004
Here is my conf.py.
preamb_old = ur'''
%\documentclass{memoir}
\makeatletter
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\fancyfoot[LO]{{\py#HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py#HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py#HeaderFamily \#title}} % here's the change
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
}
\makeatother
%\color {blue}
%\normalcolor {dark blue}
\pagecolor [RGB]{255, 247, 226}
\definecolor{VerbatimColor}{rgb}{0.95,0.85,0.65}
\definecolor{VerbatimBorderColor}{rgb}{0.5,0.95,0.1}
'''
f = open('graph/static/latexstyling.tex', 'r+')
PREAMBLE = f.read();
latex_elements = {
'papersize':'a4paper',
'pointsize':'11pt',
'classoptions': ',openany',
'babel': '\\usepackage[english]{babel}',
'preamble': PREAMBLE
}
i don't use preamble_old anymore, but it is an example of changes directly in
conf.py, to your latex preamble.
Check out latex_elements and latex_additional_files in the sphinx docs as
a starting point.

Related

How do I get rid of the "Release 1" in the Page Header of the Sphinx Latex Output?

I'm using the "manual" document class of Sphinx and I'm quite happy with how the Latex Output looks like, except for the page header. It contains the title of my paper, as well as a "Release 1".
Since I'm writing a paper and not a documentation, I clearly don't need the release information. Unfortunately, it is very hard to find information on how to customize Sphinx latex output.
Does somebody know how to do it?
To suppress the release info at the top of your Latex output, you need to set the release and latex_elements['releasename'] to empty strings in your conf.py. So you might add or modify something like this in conf.py:
release = ''
latex_elements = { 'releasename': '' }
Then the release info will be hidden.
As of Sphinx 1.5 something, the workaround of setting an empty string stopped working - at least in my case (I had used it to suppress printing "Release " on the title page) . However, setting release to a blank space does work for me. There's more discussion of it here in the Sphinx-Users group: https://groups.google.com/forum/#!topic/sphinx-users/L5PUfwVu8f0
and there was a related bug report filed: https://github.com/sphinx-doc/sphinx/pull/4411
The bellow lines eliminate also the comma in the header. Add them in your conf.py file:
latex_custom = r'''
\makeatletter
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\fancyfoot[LO]{{\py#HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py#HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py#HeaderFamily \#title}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\makeatother
'''
latex_elements = {'preamble': latex_custom}
Such a solution affects only the header.
If you want to remove the release sign also from the front page use the solution provided by ddbeck.
You can use stopwords - Stopwords are the words that will not be indexed.
http://sphinxsearch.com/docs/current.html#conf-stopwords

How do I use TrueType fonts with LaTeX

I need to use a font family in my LaTeX documents, that is available as 18 .TTF (TrueTypeFont) files.
Where do I have to copy the files in my MiKTeX 2.8 installation?
How Do I make the fonts available for LaTeX?
I usually use pdfLaTeX. I read in Truetype-Fonts in LaTeX that TTF fonts are available without creating all the .TFM files. What is necessary for this case?
Can I install the fonts in the local-texfm directory? I would like to isolate the system installation and my manually added stuff. Probably it would be easier to copy this font family on another installation.
The easiest way would be to use XeLaTeX, for which you would just install the fonts to your system. A basic template would look like this (from https://web.archive.org/web/20111115151939/http://theotex.blogspot.com/2008/04/what-is-xetex-basic-template_15.html) :
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[10pt]{memoir}
\usepackage{xltxtra,fontspec,xunicode}
\defaultfontfeatures{Scale=MatchLowercase}
\setromanfont[Numbers=Uppercase]{Hoefler Text}
\setmonofont[Scale=0.90,Ligatures=NoCommon]{Courier}
\title{Your Title}
\author{Your Name}
\date{}
\begin{document}
\maketitle
\chapter{Title}
\section{Section Title}
Your text
\subsection{Subsection Title}
Your Text
\end{document}
If you want to stick to LaTeX, you can generally try these steps:
Create the TeX font metrics (tfm), the font description (fd) and the font mapping (map).
Using ttf2tfm to generate .vpl, then vptovf to create .tfm.
Put the files (ttf, tfm, fd, map) into the proper directories in the local texmf tree.
Update the TeX filename database.
Using texhash
Register the mapping.
Using updmap-sys
It seems rather straightforward, but there are many traps regarding the font description and mapping, as well as the naming scheme for the output files.
There are a lot of scripts and howtos which didn't work for me. So I wrote this tool to help me use ttf fonts with LaTeX: http://devnotcorp.wordpress.com/2011/06/10/use-truetype-font-with-pdflatex/.
Although it's many years later I thought of adding that if one uses LuaLaTeX, you don't need to do anything apart from using the LuaLaTex package fontspec and then in the preamble of in the document \setmainfont{ComicSansMS}.
Use ttf2tfm and ttf2pk programs
try the following: http://www.radamir.com/tex/ttf-tex.htm. I tried it several YEARS ago; i found some bugs but I can't remember them anymore. I think it had something to do with wrong files being used with another program. The author had SWITCHED file extensions due to confusion because of the number of files being generated. I notified the author about it but I don't know if he had corrected it.

linebreak in url with Bibtex and hyperref package

Why is this item not shown properly in my bibliography?
#misc{ann,
abstract = {ANN is an implbmentation of nearest neighbor search.},
author = {David M. Mount and Sunil Arya},
howpublished = {\url{http://www.cs.umd.edu/~mount/ANN/}},
keywords = {knn},
posted-at = {2010-04-08 00:05:04},
priority = {2},
title = {ANN.},
url = "http://www.cs.umd.edu/~mount/ANN/",
year = {2008}
}
#misc{Nilsson96introductionto,
author = {Nilsson, Nils J.},
citeulike-article-id = {6995464},
howpublished = {\url{http://robotics.stanford.edu/people/nilsson/mlbook.html}},
keywords = {*file-import-10-04-11},
posted-at = {2010-04-11 06:52:28},
priority = {2},
title = {Introduction to Machine Learning: An Early Draft of a Proposed Textbook.},
year = {1996}
}
EDIT:
I am using
\usepackage{hyperref}
not
\usepackage{url}
. It produces error when using url package together with it. So can the two not work together?
I would like to use hyper links inside pdf file, so I want to use hyperref package instead of url package. I googled a bit, and try
\usepackage[hyperindex,breaklinks]{hyperref}
but there is still no line break just as before. How can I do it?
EDIT:
When using url and hyperref together,
if it is just
\usepackage{hyperref}
\usepackage{url}
the compilation by latex is fine, but the link is still hyperlink and has still no linebreak. If I do not use hyperref package, the link has linebreak, but I lose hyper links. Since \url can be used in both hyperref and url packages, how can I specify which package's \url is being used?
If it is
\usepackage{hyperref}
\usepackage[hyphens]{url}
the compilation by latex command will report clash with url:
! LaTex Error: Option clash for package url.
So I wonder how I should do?
You should use them in this order:
\usepackage[hyphens]{url}
\usepackage{hyperref}
You get this error when you use them the other way around.
! LaTex Error: Option clash for package url.
since the hyperref package loads the url package somewhere internally without that hypens option, and then you want to load it with the option, so it clashes.
Turning the order around does what you want and does not give this error (since the package is already loaded hyperref won't load it again with different options)
edit: this was with pdftex, I did not test with other tools.
edit2:
or as mentioned by PatrickT in a comment: \PassOptionsToPackage{hyphens}{url} if you're using a class that already loads the package, e.g. beamer.
I just ran across almost the same problem and found it solved by putting
\PassOptionsToPackage{hyphens}{url}
before the
\usepackage[...]{hyperref}
If you mean the too-wide spacing, that's because the URLs seems to not allow line-breaks. Why this happens is another question, and the answer depends on your preamble (the packages you use etc.). In principle, if properly used, the url package should allow line breaks.
EDIT
This problem (and its solution) is described here (sending you to a Google cache since the site is offline at the moment). Bottom line: either use the breakurl package, or PDFLaTeX, or both.
Weird, I load the url package (with no option) and hyphenation is done at the slashes / if needed.
Anyway, simple workaround:
howpublished = {\url{http://www.cs.umd.edu/}\url{~mount/ANN/}},
Manual job, but it splits up the URL yes or yes.
for me only this worked:
\usepackage[hyphens]{url}
\usepackage{hyperref}
...
\usepackage{biblatex}
\setcounter{biburlnumpenalty}{100}
\setcounter{biburlucpenalty}{100}
\setcounter{biburllcpenalty}{100}
Taken from: https://tex.stackexchange.com/questions/22854/url-line-breaks-with-biblatex
Normally URLs are hyphenated, but in your bibliography they seem not to be. When the URLs don't fit on one line, they are moved to the next line, and the text before them is stretched to fill out the preceding lines. Since there is only one place to break the line, it's not very likely that the preceding text will fit nicely into a whole number of lines, and so you get all the extra space.
EDIT: When you changed your bib entry, you happened to change it in such a way that the text did fit nicely. This is just a coincidence, you didn't fix your problem.
I suspect that putting
\usepackage{url}
in your preamble will solve it.
If url package doesn't help, try:
\usepackage{xurl}
\usepackage{hyperref}
Package xurl is an expanded version of url, which allows line breaking at every point in the url. Call xurl before hyperref.
Source: Does the hyperref breaklinks option have any effect?
I add this package:
\usepackage[hyphens]{url}
and in the bibtex I used:
howpublished = {**\url{**http://www.......**}**}
and it works out.
This simple solution worked for me:
\usepackage{hyperref}
\usepackage{breakurl}
The URLs are now perfect.
At the preamble, just put \usepackage{breaker} somewhere after \usepackage{hyper ref}. The \burl command is defined and, by default, the package also turns the \url command into a synonym of \burl.

How do I disable colors in LaTeX output generated from sphinx?

When I build the LaTeX file generated from sphinx, the TOC entries, and section headers are blue. Is there an easy way to disable coloring these items? If not, is there an easy way to make them black instead? My goal is to print the document on a non-color printer, and the TOC and headings do not look as dark as the rest of the text when I do so.
I would like to make one change that applies to the whole document if possible.
Note: I am using the howto document class.
Update
Thanks to ddbeck's input, I took a closer look at sphinx.sty which defines the colors that I needed to change. I set (created) the latex_elements dictionary in conf.py as follows:
mypreamble ='''
\\pagenumbering{arabic}
\\definecolor{TitleColor}{rgb}{0,0,0}
\\definecolor{InnerLinkColor}{rgb}{0,0,0}
'''
latex_elements = {
'papersize':'letterpaper',
'pointsize':'11pt',
'preamble':mypreamble
}
This worked out exactly as I wanted it. Thanks ddbeck!
You can add LaTeX by using the latex_elements['preamble'] configuration option. If you change the value of that key, you can override Sphinx's normal LaTeX. The docs on this option aren't particularly illuminating, however. You may find this thread from sphinx-dev a bit more helpful; it has more detail on how that might be used, as well as some good links for learning about LaTex (if that's something you need to get black and white output). Finally, it might help to take a look at the default .cls and .sty files.

How to force line wrapping in listings package?

I have a problem concerning the listings package in latex. I need to embed a source code of the following XML document http://www.sparxsystems.com.au/downloads/profiles/EP_Extensions.xml in my master thesis' appendix. The problem is, no matter what options I pass to the package, I don't seem to be able to fit it on the page. The lines in the listing are too long, and the listings package doesn't wrap them, which seems odd... What combination of options will do the trick?
At the moment I use the following lstset instruction:
\lstset{
breakindent=0em,
language=XML,
basicstyle=\footnotesize,
numbers=left,
numberstyle=\footnotesize,
stepnumber=2,
numbersep=5pt,
backgroundcolor=\color{white},
showspaces=false,
showstringspaces=false,
showtabs=false,
frame=single,
tabsize=2,
captionpos=b,
breaklines=true,
breakatwhitespace=true,
breakautoindent=true,
escapeinside={\%*}{*)},
linewidth=\textwidth
}
Which, with no other options set, and combined with the following command:
\lstinputlisting{EP_Extensions.xml}
Lists the given file's source to the following output:
I just had this problem...
breaklines worked for me, though you do need to set it to true - the default is false:
\lstinputlisting[style=Python,
caption=My Class,
label={mine.py},
breaklines=true,
]{../python/mine.py}
is pretty much what I used
I had this problem and this page ranks highly on google so here was the solution for me:
I had the following inclusion: \usepackage[none]{hyphenat} which causes the issue described above. I was using it to fix the problem of latex automatically breaking lines in the middle of a word, which looks really stupid in some circumstances.
After much searching for an alternative to this solution I found nothing suitable and settled for properly broken lines but badly placed hyphenation.
Not a great answer, but one idea is to word wrap the source code before including it. If you're on linux, the command fold can be used for this. Clearly this works best if the text is in a fixed width font, which i would recommend in any case for code listings.
A followup to Aaron's answer. I was using basicstyle=\ttfamily for my listings. I was therefore able to permit line breaking by changing
\usepackage[none]{hyphenat}
to
\usepackage[htt]{hyphenat}
% ^^^
The hyphenat docs describe that the htt option "enables hyphenation of ... text typeset via either \texttt or \ttfamily." In my use case, I didn't see any hyphenation in my listings, but I did get the breaking.

Resources