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/rh2pbu%24oi0%241%40ciao.gmane.io.

Reply via email to