I'm trying to get numbered figures to work on my Sphinx documentation project using latexpdf output. I installed the Sphinx numfig.py extension found here https://bitbucket.org/arjones6/sphinx-numfig
However, whenever I use the :num: tag that is supposed to provide a cross reference with the figure's number I instead get the following
rst
.. _fig_logo:
.. figure:: logo.*
Example of a figure
Reference to logo :num:`figure #fig_logo`
Generates output:
Reference to logo figure ??
Am I doing something wrong?
Seems that if you have an underscore in your label name (like in fig_logo) sphinx replaces this with a minus (-, this makes sense as latex sometimes behaves strange in cases whit underscores), while the reference still uses the underscore.
For that reason latex can not find the label referenced.
This is the resulting tex code generated by sphinx:
\includegraphics{logo.png}
\caption{Example of a figure}\label{index:fig-logo}\end{figure}
Reference to logo \hyperref[index:fig_logo]{figure \ref*{index:fig_logo}}
(Note the difference between fig-logo as label and fig_logo as reference.)
If you replace the underscore by a minus for instance
.. _fig-logo:
.. figure:: logo.png
Example of a figure
Reference to logo :num:`figure #fig-logo`
the tex code looks like this:
\includegraphics{pandas_bar.png}
\caption{Example of a figure}\label{index:fig-logo}\end{figure}
Reference to logo \hyperref[index:fig-logo]{figure \ref*{index:fig-logo}}
and in the pdf generated this is resolved to
Reference to logo figure 1
Update
If you don't want to change all the labels you can update numfig: it should be sufficient to add the line
target = target.replace('_', '-')
just before line 27 in your copy of the extension.
I opened an issue on bitbucket.
Related
When creating a new powerpoint slide with a line chart on it, I keep getting a chart title even though I didn't ask for one. I have tried all sorts of ways to get rid of it using combinations of chart.has_title=False or chart.has_text_frame = False and nothing seemed to work.
I looked at the diff between the xml when the chart was working well and now when it display this unwanted title. Among other things, there was this <c:autoTitleDeleted val="0"/> property. In the python-pptx chart.xmlwriter source code itself I changed the value to 1 and the chart title disappeared so I assume this is the root cause of this unwanted titleāI have no idea why the autoTitleDeleted element is now being added to the xml from python-pptx.
I also saw this issue https://github.com/scanny/python-pptx/issues/460, but when I try to implement the fix I get the following error:
autoTitleDeleted = chart_element.get_or_add_autoTitleDeleted()
AttributeError: 'CT_Chart' object has no attribute 'get_or_add_autoTitleDeleted'
And I can't find in the docs anywhere a get_or_add_audoTitleDeleted method nor in the source code.
I also tried changing the xml manually by simply doing this:
chart._element.xml = xml.replace('autoTitleDeleted val="0', 'autoTitleDeleted val="1')
But I get a AttributeError: can't set attribute
So I have 3 questions:
1) How can I resolve this?
2) For the future, when I find the xml causing an issue, how can I manually change it? Is there a library somewhere for xml manipulation?
3) Why is this autoTitleDeleted element being added in the first place?
I would check your python-pptx version. This new attribute was added quite recently just for this reason. I recommend upgrading to the latest version 0.6.18 and see what happens. The fact that the traceback reports not finding that attribute is the evidence of a prior version. You can see the code that provides that attribute here:
https://github.com/scanny/python-pptx/blob/master/pptx/oxml/chart/chart.py#L40
I'm building my python package documentation as HTML and as a latex PDF. The default latex pdf generated (manual class) has a large amount of white space at the top of the table of contents around the text "CONTENTS". I'm not super familiar with latex so when I've look at the generated .tex file I don't see anything that tells me how to remove the whitespace.
I've searched around and couldn't find a latex solution that worked. I also tried setting the :caption: on the toctree to an empty string, but that actually removes the entire TOC and all of my content.
Can anyone help me with this?
The default behaviour of Sphinx for English language is to use Bjarne option to LaTeX package fncychap for chapter headings. But it also loads package titlesec for generally speaking title headings. It does not make a special chapter definition with titlesec, which simply gather the fncychap definition and wraps it in its own hooks. Anyway, making the story short we find
\ttl#save#mkschap #1->\vspace *{50\p# }{\parindent \z# \raggedright \normalfont \interlinepenalty \#M \DOTIS {#1} \vskip 40\p# }
in a log trace and this is the fncychap definition of \#makeschapterhead as preserved by titlesec in its own macro \ttl#save#mkschap.
fncychap is loaded before sphinx.sty, there is no hook,
edit: in fact the 'fncychap' key whose default value is '\\usepackage[Bjarne]{fncychap}' could serve to add some code to redefine the fncychap setting for un-numbered chapter titles. It is not that different from the approach with 'preamble' key below, except that one would not have needed knowing about titlesec intervention in all this.
but since recent Sphinx 1.5 you can use your own Jinja template for latex content. From the look of your contents which is small, I think you have an older version of Sphinx thus I will go for the LaTeX hacking variant something like this:
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
'preamble': r"""
\makeatletter
\def\ttl#save#mkschap #1{\vspace *{10\p# }{\parindent \z# \raggedright
\color{blue}%
\normalfont \interlinepenalty \#M \DOTIS {#1} \vskip 10\p# }}
\makeatother
""",
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
I have added a \color{blue} in there for demonstration purposes only, and modified the \vspace and \vskip commands which is what you need.
The image shows however that there is some extra source of vertical space between Contents and the TOC contents (it remains even with \vskip 0\p# but one can do \vskip -40\p# ...), but I think you are after the top space above Contents and already using only \vspace*{10pt} reduced it a lot (not visible in screenshot below).
I am trying to use an existing template design of powerpoint using python-pptx library. My problem is that I have two or more different templates ready and when I viewed their slide master, the "title and content layout" of each template are not on the same order. So, the index that I will use will be 1 if I used the first templates and 2 for the second templates.
Using the python-pptx library:
Sample Python Code 1 for fist templates
bullet_slide_layout = self.prs.slide_layouts[1]
Sample Python Code 2 for second templates
bullet_slide_layout = self.prs.slide_layouts[2]
Both of them works, but I do not want to change the indices every now and then whenever a new template design is added.
Please help. Also, If I am not clear with the problem I presented, please tell me. Thank you
If you want to retrieve a slide layout by something other than its position in the layout sequence, you will have to write something of your own.
There are a few approaches:
Use the slide layout name
Use the slide layout id
Characterize the slide by the number and type of placeholders it contains and perhaps their size and position.
So as an example, something simple would be:
def get_layout_by_name(prs, layout_name):
for layout in prs.slide_layouts:
if layout.name == layout_name:
return layout
return None
I started working with doxygen to generate the documentation of my Python code.
I use doxypy filter to preprocess the Python docstrings.
My goal is to have a nice syntax highlighting of doxygen comments in Python.
When writing my mainpage in a dedicated .dox file, I found that the doxygen comments can be highlighted in vim with the following command:
set syntax=c.doxygen
I tried the same command for Python but I got nothing:
set syntax=python.doxygen
I also made some googling and couldn't find anything interesting
Here is a typical piece of code I'd like to highlight:
class CompilationTab:
"""
The compilation tab of the verif GUI. It contains the layout description
and the functions required to deal with specific behaviors of the tab
"""
def __init__(self, notebook, tab_name):
"""
The class constructor.
#param notebook Notebook: The parent #c Notebook widget
#param tab_name String: The display name of the tab
"""
Does anybody already fixed this issue?
Thank you for help!
If you look into syntax/doxygen.vim you can read in the preamble of the file that currently only
cpp, c, idl, doxygen and php
files are supported.
Since doxygen.vim works a lot with the syn region command i searched for the line that defines the multiline string in syntax/python.vim.
The interesting part of the command that defines this region is
syn region pythonString start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
Derived from that what is in doxygen.vim and the above line you can add the following lines
"delete the following line if you don't want to have enhanced colors
let g:doxygen_enhanced_color=1
runtime! syntax/doxygen.vim
syn region doxygenComment matchgroup=pythonString start=+[uU]\=\z('''\|"""\)+ end="\z1" contains=doxygenSyncStart,doxygenStart,doxygenTODO keepend fold containedin=pythonString
to ~/.vim/after/syntax/python.vim or execute them by hand.
In addition you may have to customize the colors of the added doxygen highlighting groups by hand. At least i would do so since the resulting look doesn't conform with my taste.
Perhaps the fold argument of the syn command is of special interest for you. If you set foldmethod to syntax you can fold and unfold the multiline comments. That seems to be useful if you could no longer stand the view of those colors and are to lazy to adjust them :)
without doxygen highlighting:
with doxygen highlighting and g:doxygen_enhanced_color == 1:
I'm using python Textile to store markup in the database. I would like to yield the following HTML snippet:
(<em>asdf</em>)
The obvious doesn't get encoded:
(_asdf_) -> <p>(_asdf_)</p>
The following works, but yields an ugly space:
( _asdf_) -> <p>( <em>asdf</em>)
Am I missing something obvious or is this just not possible using python Textile?
It's hard to say if this is a bug or not; in the form on the Textile website, (_foo_) works as you want, but in the downloadable PHP implementation, it doesn't.
You should be able to do this:
([_asdf_]) -> <p>(<em>asdf</em>)</p>
However, this doesn't work, which is a bug in py-textile. You either need to use this:
(]_asdf_])
or patch textile.py by changing line 918 (in the Textile.span() method) to:
(?:^|(?<=[\s>%(pnct)s])|([{[]))
(the difference is in the final group; the brackets are incorrectly reversed.)
You could also change the line to:
(?:^|(?<=[\s>(%(pnct)s])|([{[]))
(note the added parenthesis) to get the behavior you desire for (_foo_), but I'm not sure if that would break anything else.
Follow up: the latest version of the PHP Textile class does indeed make a similar change to the one I suggested.