I'm using Sphinx and restructured text to generate a PDF with tables in it. I'd like to specify the table option to the xcolor package so I can use \rowcolors to achieve an alternating row color scheme.
Reviewing Sphinx documentation for adding packages, it appears I should use the preamble key in the latex_elements configuration to add my custom latex:
\usepackage[table]{xcolor}
\rowcolors{2}{blue!10}{white}
However, when I do that, I get the error:
! LaTeX Error: Option clash for package xcolor
Looking at the .tex file output by Sphinx, it appears the clash comes from \usepackage[,numfigreset=2,mathnumfig]{sphinx}, because the sphinx.sty class requires the xcolor package, which gets imported without any options.
I can get this to work by manually editing the .tex output and moving my \usepackage[table]{xcolor} above the sphinx package import line, but there doesn't appear to be any way to achieve that via my conf.py.
Sphinx added an extrapackages key that places custom latex prior to the hyperref package import, but that is still after the sphinx package import.
I've also tried the passoptionstopackages key, which adds the latex \PassOptionsToPackage{table}{xcolor}, but this also doesn't work when it comes after the initial import of xcolor.
I think I have three main questions:
Is there another way to achieve an alternating row coloring scheme for tables in a PDF with Sphinx?
Does anyone know why the extrapackages key only places package import above hyperref and not others?
Is there a way to include custom latex or override Sphinx-generated latex above where extrapackages places it?
Related
I am using Windows 10 with Anaconda and Spyder 4. When using matplotlib, I would like to use the font Proxima Nova and render with LaTeX.
If in my matplotlibrc file I specify
font.family : Proxima Nova
then the figure renders with the font Proxima Nova. This means that the font is installed on my system (as it is) and matplotlib can use it. However, if in the matplotlibrc file I also specify
text.usetex: True
then, even though I have specified Proxima Nova as the font, the figure renders in the default LaTeX font, which I guess is Computer Modern.
I have tried
matplotlib.font_manager._rebuild()
In the source code file and also have tried specifying the fonts in the source code file and not in the matplotlibrc file. However I always get the same result. I have also followed all the advice on this help page, including making sure that latex, dvipng and ghostscript are all the PATH variable. However nothing seems to work.
I would like to note that I can use Proxima Nova separately when compiling Latex documents, so that should not be an issue either.
How can I get matplotlib to be able to use a non-default font and render with LateX at the same time?
After some further investigation, I was able to get to use Proxima Nova with Latex, although there are still some outstanding issues.
The main issue is that if the font Proxima Nova is used with Latex, one needs to use Lualatex and not plain Latex. Here is the Matplotlib instruction on using matplotlib with Lualatex.
The key to getting things to work was this post.
At the very beginning of my .py file, I have the following code:
import matplotlib as mpl
mpl.use("pgf")
mpl.rcParams.update({
'font.family': 'sans-serif',
'text.usetex': True,
'pgf.rcfonts': False,
'pgf.texsystem': 'lualatex',
'pgf.preamble': r'\usepackage{fontspec} \setmainfont{Proxima Nova}',
})
The code above should be placed at the very top of the code, above any other imports.
The problem, however is that this solution works only after performing the following steps:
Delete the .matplotlib/tex.cache folder and restart spyder
Replace 'font.family': 'sans-serif' and \setmainfont{Proxima Nova} with 'font.family': 'serif' and \setmainfont{Times New Roman} respectively. Run python once.
Revert back to 'font.family': 'sans-serif' and
\setmainfont{Proxima Nova} and run python again.
The output with the correct font is produced.
Unless the above 4 steps are performed, the output is compiled with the default DejaVu Sans font and not with Proxima Nova. I am not sure why...
After getting help on the matplotlib github forum, I was pointed to the following solution:
mpl.rcParams.update({
'font.family': 'sans-serif',
'text.usetex': True,
'pgf.rcfonts': False,
'pgf.texsystem': 'lualatex',
'pgf.preamble': r'\usepackage{fontspec} \setsansfont{Proxima Nova}',
})
In other words you need to use setsansfont in stead of setmainfont. You can see the matplotlib forum page here.
basically the title is the question:
I would like to use lualatex for all the text handling in a matplotlib plot without using the pgf backend.
I need fontenc package and customized fonts to have identical fonts in plots and in my latex documents but do not want to use the pgf backend.
Is there a hidden option somewhere?
The context is the following: I have a mycommands.sty file where all my defind \newcommand for math are stored. I use some specific fonts for, e. g., \mathscr{p}, which is not possible (small letter) without the fontenc package.
Now I want to use these custom commands in different places (legend, labels, title, ...) in the plot and have them work and look exactly the same as in the document I write and compile with lualatex.
The only point why it is not possible is that matplotlib internally uses pdflatex for the compilation which gives me errors when using fontenc and therefore some of my commands do not work.
Thanks.
Short version: I would like to use a font set to REPLACE Glyphicons without also including Glyphicons CSS, and without modifying the source bootstrap.less file.
Long version:
Using Bootstrap's own Grunt file and source files as a base, by default a build process will include Glyphicons in the compiled CSS file.
Since I do not plan to use Glyphicons at all, the "lowest hanging fruit" for me is to go ahead and compile this way, but also include the font I will be using (for example, Font Awesome).
However, the more "elegant" way will be to only include the replacement font.
I can modify bootstrap.less, which includes this line:
#import "glyphicons.less";
such that the Font Awesome less file is used instead. However, the problem with this is that I am using Bootstrap as an "untouchable library" not as a modifiable source file. I want to be able to drop in new versions of Bootstrap at a moment's notice without the need to remember to change this modified line.
Does Grunt have the concept of "replace string A with string B in memory before the compile runs"? Or is there another way to accomplish my goal? Or should I just not worry about it and include both sets of compiled CSS?
I think you can use grunt-string-replace
https://github.com/erickrdch/grunt-string-replace
Does the Sphinx documentation tool offer different PDF themes like it offers different HTML themes?
I Googled the issue but can't find an answer, which leads me to believe the answer is 'no'. Still, i thought i'd ask here.
Thanks.
Firstly, Sphinx doesn't generate PDF output by itself, though there are three general methods to get from Sphinx source files to PDF output:
Use the Latex builder, and then a separate tool like latex2pdf to generate the PDF output
Use the Sphinx plugin from the rst2pdf project
Use the rinoh Sphinx builder provided by rinohtype
That being said there is lots of potential for customizing the styling of your PDF output using either method.
When using the latex->pdf method, you can customize your latex output using a number of options in your sphinx config file. See here. This method is somewhat less convenient than the HTML themes that Sphinx uses for HTML generation, though (IMO).
When using rst2pdf you can define your own stylesheet, which is described in more detail in the manual (look under the "Styles" heading). rst2pdf includes a number of stylesheets, which can be combined for various results. And of course, you can also modify them or create your own (they're just JSON files). These stylesheets also support a kind of inheritance, so act more like the Sphinx HTML themes than the previous method.
rinohtype has extensive provisions for styling a document. See the Basic Document Styling and subsequent sections of the rinohtype manual.
There are no predefined themes for PDF output for Sphinx. But LaTex offers a rich set of options to style the document. My problem was to find the proper way to style the document with sphinx. Here the way, which worked for me:
First take a look into the conf.py. There you'll find an option latex_elements. With this option you can add your own LaTex commands to the output. For example:
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
'pointsize': '12pt',
'fontpkg': r"""
\PassOptionsToPackage{bookmarksnumbered}{hyperref}
""",
# Additional stuff for the LaTeX preamble.
'preamble': r"""
\usepackage{setspace}
""",
'footer': r"""
""",
'maketitle': r'''
\pagenumbering{arabic}
''',
}
There are a few points important to know.
Use r""" to avoid conflicts with python
Though preamble would be the right point to add \usepackage you can have conflicts with the Sphinx default settings. Look at fontpkg in the example. It is the first include in the .tex output document. If you have to set options for default packages, do it here.
maketitle let you define your own title page. See some latex documentation. I set \pagenumbering there to have the table of contents with arabic numbers, so the real content begins on page "1".
With the right knowledge of Latex commands you can get good theming with a few commands. A good source to find help is https://tex.stackexchange.com/ where most common problems have a solution. But finding the proper Latex commands is much more difficult than to choose a theme as done for HTML.
It might be helpful to take a look in the Tex-Output under ./_build. There you can see, how the latex_elements-options were included in the document.
So I thought it'd be clever of me to split my WIX file up into various smaller files. I did this for a couple reasons. One being that it would make it easier to maintain. Anyway, regardless of my reason, I put the components in one file. But when I compile, I now get a warning that says:
warning LGHT1079: The cabinet 'media1.cab' does not contain any files. If this installation contains no files, this warning can likely be safely ignored. Otherwise, please add files to the cabinet or remove it.
Now the Media element is in the main wix file and all of my File components have a DiskId that matches. So I thought I'd just stick the Media element in the same fragments as where I define my components. No dice. I get a warning that says that the installer has no media.
So do I have to define all of my components in the same file? Or am I missing something?
I figured out what I did wrong. I also put the features in a separate file. I needed to add a FeatureRef tag for each feature within the product tag.
Your Feature elements will need ComponentRef or ComponentGroupRef elements to associate the components to the features.