I came up with what seemed to me to be a simpler solution. I put the macros 
in my preamble.rst between two comment lines that I could recognize and 
remove easily using sed. I then used a wrapper script to build the pdf that 
fist removed the macors in preamble.rst, then build the pdf, and then 
replaced the original preamble.rst. Here is my preamble.rst:

    .. |space| unicode:: 0xA0 
    .. |tab| replace:: |space| |space| |space| |space| 
     
    .. comment BEGIN_LATEX_MACROS 
        These latex macros must also be defined in latex_elements in 
conf.py 
     
    .. rst-class:: hidden 
     
        :math:`\newcommand{\B}[1]{ {\bf #1} }` 
        :math:`\newcommand{\R}[1]{ {\rm #1} }` 
     
    .. comment END_LATEX_MACROS 

My problem is that I would like to use ReadtheDocs to display my 
documentation, but I do no know how to get it to run a script between 
building the html and build the pdf ?

Perhaps there is a way in preamble.rst to conditionaly include the macros 
depending on if latex or html conversion is being done ?

On Wednesday, November 25, 2020 at 8:34:57 PM UTC-7 ds04...@gmail.com wrote:

> On Wed, Aug 12, 2020, 5:19 AM bradley...@gmail.com <bradley...@gmail.com> 
> wrote:
>
>> 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}`
>>
>> This File
>> *********
>> .. literalinclude:: index.rst
>>
>> -- 
>> 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...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sphinx-users/92312617-c0dc-4c14-9d41-068e79f7bd76n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/sphinx-users/92312617-c0dc-4c14-9d41-068e79f7bd76n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/e9e4ce70-4e21-4665-8104-81b0d9f87c38n%40googlegroups.com.

Reply via email to