Jupyter-book: Defining TeX macros for MathJax

Created on 19 May 2020  路  13Comments  路  Source: executablebooks/jupyter-book

I was wondering where I can add TeX macros such as the ones here for the whole book.

Currently, I can add the macros at the beginning of each file but it would be great to define them in one location for the whole book.

Most helpful comment

I made the following changes under _config.yml and the new commands worked fine

sphinx:
  extra_extensions          : ""
  config                    :
    mathjax_config          :
      TeX                   :
        Macros              :
          "N"               : "\\mathbb{N}"
          "Z"               : "\\mathbb{Z}"
          "R"               : "\\mathbb{R}"
          "Z"               : "\\mathbb{Z}"

All 13 comments

Hey @bsamadi I just came across this mathjax_config option on the Sphinx doc website. Thought it might be useful for defining TeX macros.

I made the following changes under _config.yml and the new commands worked fine

sphinx:
  extra_extensions          : ""
  config                    :
    mathjax_config          :
      TeX                   :
        Macros              :
          "N"               : "\\mathbb{N}"
          "Z"               : "\\mathbb{Z}"
          "R"               : "\\mathbb{R}"
          "Z"               : "\\mathbb{Z}"

perfect! think you could open a docs PR here for it? https://jupyterbook.org/advanced/sphinx.html

I think this was closed by #618 !

Is there a way to add a function with arguments? Thanks!

Hey @dafriedman97, on this page, I saw this example:

MathJax.Hub.Config({
TeX: {
Macros: {
RR: "{\bf R}",
bold: ["{\bf #1}",1]
}
}
});

I was looking for a DeclareMathOperator equivalent. For now, I have defined the sign function like this:

"sign" : "\mathop{\rm sgn}nolimits"

That works -- thanks!

@dafriedman97 I made sure to include an example in the documentation here.

I have included this macro in _config.yml:

sphinx:
extra_extensions : ""
config :
mathjax_config :
TeX :
Macros :
"bmat" : "{\\begin{bmatrix}}"
"emat" : "{\\end{bmatrix}}"

It doesn't work. See this page (right before the Python code):
http://bsamadi.github.io/cvxguide/SecondOrderConeProgram.html

However, when I include it inside the page as:

'''{math}
newcommand{bmat}{left[begin{array}}
newcommand{emat}{end{array}right]}
'''

It works, see this page for example:
http://bsamadi.github.io/cvxguide/QuadraticProgram.html

Hey @bsamadi, I just tried the following:

sphinx:
  config:
    mathjax_config:
      TeX:
        Macros:
          "bmat" : ["\\left[\\begin{array}"]
          "emat" : ["\\end{array}\\right]"]

and this is the output
Screen Shot 2020-05-28 at 11 02 36 PM

Thank you @najuzilu. The problem was the outer brackets. After looking at your example, I removed them. It would be great to add this to the documentation. Thank you so much!

@choldgraf do you think we should include this example under the cheatsheet #637 or add it as an example in the documentation here.

I think here: https://jupyterbook.org/advanced/sphinx.html?highlight=latex#defining-tex-macros makes the most sense 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spring-haru picture spring-haru  路  5Comments

nozebacle picture nozebacle  路  3Comments

rickwierenga picture rickwierenga  路  3Comments

firasm picture firasm  路  5Comments

akhmerov picture akhmerov  路  5Comments