I am trying to get the same source code to produce both the html pages and 
a pdf document. I think this is one of the advantages of sphinx ? I was not 
expecting the scope of commands to be different for the two cases, html and 
pdf.

I am using a file called preamble.rst to get my definitions for the entire 
document inside each html page (this includes other commands besides latex 
command). If I use the latex_elements as suggested above, I have to include 
the definitions in preamble.rst to build html files and remove them to 
build latexpdf files. While this doable, it would seem there should be a 
simpler way.

Perhaps I should ask this with another conservation ?
I have noticed something strange in the latexpdf output (now that I can get 
it) . The table of contents in the pdf file only seems to include the 
toctree command in the index.rst file, and not the toctree commands in 
other files that get included. I am using the Read The Docs theme and the 
htm_theme_options has 'titles_only' is set to True.


On Thursday, August 13, 2020 at 12:16:22 AM UTC-7 jfbu wrote:

> Hi,
>
> Le 12/08/2020 à 14:19, bradley...@gmail.com a écrit :
> > The index.rst file below demonstrates that \newcommand does not work 
> with latexpdf.
> > 
> > ------------ Below is my conf.py file ------------------------
> > # For conf.py documentation see
> > # http://www.sphinx-doc.org/en/master/config
> > #
> > project   = 'newcommand'
> > extensions = [
> >     'sphinx.ext.mathjax',
> > ]
> > ------------- Below is my index.rst file -------------------------
> > Problem With \newcommand in latexpdf
> > ####################################
> > This file builds just file,
> > and displays as intended, with ``make html``,
> > but with ``make latexpdf`` it generates and
> > ``Undefined control sequence.`` error for the
> > macro ``\B``.
> > 
> > Define Latex Macro
> > ******************
> > ``:math: \newcommand{\B}[1]{{\bf #1}}``
> > :math:`\newcommand{\B}[1]{{\bf #1}}`
> > 
> > Use Latex Macro \B
> > ******************
> > ``:math: f : \B{R} \rightarrow \B{R}``
> > :math:`f : \B{R} \rightarrow \B{R}`
> > 
>
> the LaTeX has scope limiting constructs such as "environments"
> but also equations, inclusive of inline mathematics
>
> (delimited in the file in LaTeX mark-up produced by make latex by \( ... 
> \) delimiters)
>
> you must locate the \newcommand outside of such scope delimited location
>
> either via
>
> .. raw:: latex
>
> \newcommand{\B}[1]{{\bf #1}}
>
> before it is used (and only once)
>
> or in conf.py
>
> latex_elements = {
> 'preamble': r"\newcommand{\B}[1]{{\bf #1}}",
> }
>
> which is a priori better location, recommended for that usage.
>
>
> Once this is done do not put any other \newcommand{\B} as this will 
> generate an error.
>
> Notice that \bf mark-up has been deprecated by LaTeX developers
> and perhaps {\mathbf{#1}} is more legit
>
> latex_elements = {
> 'preamble': r"\newcommand{\B}[1]{\mathbf{#1}}",
> }
>
>
> or, if you use xelatex with unicode-math, perhaps \symbf
>
>
> Besides LaTeX normative gurus will try to discourage you to define a 
> one-letter
> command such as \B. (the rationale being that depending on language perhaps
> the one-letter command has a meaning already ; anyway if it does the 
> \newcommand
> will then raise an error so you will know).
>
>
> Jean-François
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sphinx-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/5ae0887c-7d93-4fa1-bdb7-63c0b8efd5dcn%40googlegroups.com.

Reply via email to