How to use latex packages?

1,468 views
Skip to first unread message

Johan Ekh

unread,
Jan 25, 2011, 6:14:25 AM1/25/11
to sphin...@googlegroups.com
Hi,
I'm trying to use latex packages in Sphinx but I can't get it to work.

I've put the following in my conf.py

latex_preamble =[
    ('\\usepackage{amssymb}',
     '\\usepackage{amsmath}',
     '\\usepackage{amsxtra}',
     '\\usepackage{bm}'),
]

and it works when I generate html (with pngmath) with "make html".

However, when I use "make latexpdf" I get the error below. Does anyone
know what I should do?

Best regards,
Johan



sphinx-build -b latex -d build/doctrees   source build/latex
Running Sphinx v1.0.5
loading pickled environment... done
building [latex]: all documents
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
processing cabletlk.tex... index intro tutorial userguide theory modules changes todos
resolving references...
writing... done
copying TeX support files... done
build succeeded.
Running LaTeX files through pdflatex...
make -C build/latex all-pdf
make[1]: Entering directory `/home/johan/Source/Python/swProjects/cableFatigue/doc/build/latex'
pdflatex  'cabletlk.tex'
This is pdfTeX, Version 3.141592-1.40.3 (Web2C 7.5.6)
entering extended mode
(./cabletlk.tex
LaTeX2e <2005/12/01>
Babel <v3.8h> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, arabic, basque, bulgarian, coptic, welsh, czech, slovak, german, ng
erman, danish, esperanto, spanish, catalan, galician, estonian, farsi, finnish,
 french, greek, monogreek, ancientgreek, croatian, hungarian, interlingua, ibyc
us, indonesian, icelandic, italian, latin, mongolian, dutch, norsk, polish, por
tuguese, pinyin, romanian, russian, slovenian, uppersorbian, serbian, swedish,
turkish, ukenglish, ukrainian, loaded.
(./sphinxmanual.cls
Document Class: sphinxmanual 2009/06/02 Document class (Sphinx manual)
(/usr/share/texmf/tex/latex/base/report.cls
Document Class: report 2005/09/16 v1.4f Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size10.clo)))
(/usr/share/texmf/tex/latex/base/inputenc.sty
(/usr/share/texmf/tex/latex/base/utf8.def
(/usr/share/texmf/tex/latex/base/t1enc.dfu)
(/usr/share/texmf/tex/latex/base/ot1enc.dfu)
(/usr/share/texmf/tex/latex/base/omsenc.dfu)))
(/usr/share/texmf/tex/latex/base/fontenc.sty
(/usr/share/texmf/tex/latex/base/t1enc.def))
(/usr/share/texmf/tex/generic/babel/babel.sty
(/usr/share/texmf/tex/generic/babel/english.ldf
(/usr/share/texmf/tex/generic/babel/babel.def)))
(/usr/share/texmf/tex/latex/psnfss/times.sty) (./fncychap.sty)
(/usr/share/texmf/tex/latex/tools/longtable.sty)
! Undefined control sequence.
\\  ->\let \reserved@e
                       \relax \let \reserved@f \relax \@ifstar {\let \reserv...
l.12 ...usepackage{amsxtra}', '\\usepackage{bm}')]
                                                 
?

Kevin Dunn

unread,
Jan 25, 2011, 10:09:37 AM1/25/11
to sphin...@googlegroups.com
On Tue, Jan 25, 2011 at 06:14, Johan Ekh <ekh....@gmail.com> wrote:
> Hi,
> I'm trying to use latex packages in Sphinx but I can't get it to work.
>
> I've put the following in my conf.py
>
> latex_preamble =[
>     ('\\usepackage{amssymb}',
>      '\\usepackage{amsmath}',
>      '\\usepackage{amsxtra}',
>      '\\usepackage{bm}'),
> ]
>
> and it works when I generate html (with pngmath) with "make html".
>
> However, when I use "make latexpdf" I get the error below. Does anyone
> know what I should do?

Hi Johan,

The ``latex_preamble`` has been deprecated - see here:
http://sphinx.pocoo.org/latest/config.html#confval-latex_preamble

As recommended in the docs, you should rather use a ``latex_elements``
dictionary.

For example, my documentation uses this idea in ``conf.py``

_PREAMBLE = r"""
\usepackage{amsmath}
"""
latex_elements = {
'preamble': _PREAMBLE,
# other settings go here
}

Please try that and see if it works better.

By the way, the sphinx.sty file imports "amsmath" already, so you can
leave that one out.
Kevin

> --
> You received this message because you are subscribed to the Google Groups
> "sphinx-dev" group.
> To post to this group, send email to sphin...@googlegroups.com.
> To unsubscribe from this group, send email to
> sphinx-dev+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sphinx-dev?hl=en.
>

Johan Ekh

unread,
Jan 26, 2011, 5:19:41 AM1/26/11
to sphin...@googlegroups.com
Thanks Kevin,
it works!

Would you also know if it is possible to use latex in general, i.e. without ".. math::"?
Can I use pstricks to generate my graphics?


Best regards,
Johan

Kevin Dunn

unread,
Jan 26, 2011, 8:10:06 AM1/26/11
to sphin...@googlegroups.com
On Wed, Jan 26, 2011 at 05:19, Johan Ekh <ekh....@gmail.com> wrote:
Thanks Kevin,
it works!

Great.
 
Would you also know if it is possible to use latex in general, i.e. without ".. math::"?

I'm not 100% clear about your question.  You can always include LaTeX code directly in your RST using the 

.. raw:: latex

    % your LaTeX/pstricks code here

directive.  But those sections won't appear in HTML, or other output formats.  If your concern however is that typing ``.. math::`` and ``:math:`` is too much of an overhead, when compared to LaTeX's \[... \] and $...$ for math heavy documents, then your should write a macro in your text editor (e.g. Ctrl-M) to generate that RST code for you. 

The advantage of Sphinx is of course that you can generate great HTML, PDF and other output formats.  Using those math roles and directives is a small price to pay to help the HTML generator, LaTeX generator, etc know what you want to do.


Can I use pstricks to generate my graphics?

I will reply to your other posting separately.

Hope that helps,
Kevin

Johan Ekh

unread,
Jan 26, 2011, 8:36:11 AM1/26/11
to sphin...@googlegroups.com
Thank you Kevin!
Sorry for not beeing clear, but you answered my question anyway.
Using the .. raw directive means that the latex stuff don't appear in
html which I wanted it to do. I want to produce html and pdf from the
exacr same source.

I will look at your answer in the other posting!

Johan

shaunc

unread,
Mar 6, 2011, 4:06:44 PM3/6/11
to sphinx-dev

> If your concern however is that typing ``.. math::`` and
> ``:math:`` is too much of an overhead, when compared to LaTeX's \[... \] and
> $...$ for math heavy documents, then your should write a macro in your text
> editor (e.g. Ctrl-M) to generate that RST code for you.
>

BTW, if you don't use `` for python markup, you can use

.. default-role:: math

to shorten :math:`foo` to `foo`.

-- Shaun

Vivian De Smedt

unread,
Mar 15, 2011, 10:55:03 AM3/15/11
to sphin...@googlegroups.com
Dear All,

We write our documentation using Sphinx.
But some of us are abroad with no source control access and they would
like to edit the doc via their web browser.
So I wanted to transform the static Sphinx set of pages into a wiki.

Because it looked no so difficult I did it.
Now I wondered if some others had the same desire and if so what are
solutions they found.
Maybe could I reuse it and get something more sophisticated that what I
built (it is fairly basic).

If someone is interested to the small wsgi application I built I'll be
glad to share it.
And if you think it could be a valuable addition to Sphinx I'll be
delighted to give it to the project.

Yours,
Vivian.

JohnKitchin07

unread,
Mar 17, 2011, 9:11:48 AM3/17/11
to sphinx-dev
You might check out the Numpy documentation project (http://
docs.scipy.org/numpy/Front%20Page/). I think they have a wiki/rst/
sphinx like solution for editing documentation (http://code.google.com/
p/pydocweb/) that is written in Django.

j

Vivian De Smedt

unread,
Mar 19, 2011, 5:45:11 PM3/19/11
to sphin...@googlegroups.com
John,

Thanks for the pointer. I'll have a look.

Cheers,
Vivian.


On 17/3/2011 14:11, JohnKitchin07 wrote:
> (http://code.google.com/
> p/pydocweb/

Ashwin Kumar

unread,
Oct 14, 2016, 7:41:31 PM10/14/16
to sphinx-users, sphin...@googlegroups.com
Hi Vivian,

I'm interested in doing something similar too. Can you please share your wsgi application with me?

Thanks,
Ashwin
Reply all
Reply to author
Forward
0 new messages