\Bold command definition in every LaTeX output

249 views
Skip to first unread message

AlbertHilb

unread,
Dec 19, 2021, 9:34:13 AM12/19/21
to sage-devel
Hi all.

I noted every command LaTeX output is prefaced by the definition of a \Bold newcommand even if the \Bold command is not really used in the output.
For example, if I type "1" and press return I get

\newcommand{\Bold}[1]{\mathbf{#1}}1

Is this intended?

Among other things, the presence of the newcommand definition prevent me from using KaTeX as LaTeX renderer because it complains \Bold command already exists and \renewcommand should be used to redefine it.

I use SageMath 9.4 binary for Ubuntu 20.04 64 bit with jupyterlab 3.2.4 as frontend.

dmo...@deductivepress.ca

unread,
Dec 19, 2021, 3:55:55 PM12/19/21
to sage-devel
Yes, this is the intended behaviour.  If you don't like it, then, as a workaround, you could try to clear the variable called "sage_configurable_latex_macros".  YMMV, but this works for me in a fresh sage session:
    sage: from sage.misc.latex_macros import sage_configurable_latex_macros
    sage: global sage_configurable_latex_macros
    sage: sage_configurable_latex_macros.remove("\\newcommand{\\Bold}[1]{\\mathbf{#1}}")
If I now type "html(x)", then the result is "<html>\[x\]</html>", instead of "<html>\[\newcommand{\Bold}[1]{\mathbf{#1}}x\]</html>".

If that gives errors due to a bad definition of "\\Bold", then maybe you should also do:
    sage: sage_configurable_latex_macros.append("\\renewcommand{\\Bold}[1]{\\mathbf{#1}}")

AlbertHilb

unread,
Dec 20, 2021, 6:06:05 AM12/20/21
to sage-devel
Problem solved! Thank you very much!

Eric Gourgoulhon

unread,
Dec 21, 2021, 5:49:11 AM12/21/21
to sage-devel
Hi,

Le lundi 20 décembre 2021 à 12:06:05 UTC+1, AlbertHilb a écrit :
Problem solved! Thank you very much!

That being said, it seems to me that these \newcommand{Bold} in each LaTeX output (!) are  an unnecessary pollution of  the Jupyter notebooks in %display latex mode. Unless there might be a reason for it, why not replacing lines like
return r"\Bold{Q}"
by
return r"\mathbf{Q}"
in the relevant  _latex_ methods ? (the above example is line 279 of src/sage/rings/rational_field.py)

Eric.


Dima Pasechnik

unread,
Dec 21, 2021, 6:59:57 AM12/21/21
to sage-devel
I would vote for updating our LaTeX methods to use more standard macros.

--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/d56a3258-a95e-49b4-beb8-b38ed7493014n%40googlegroups.com.

Matthias Koeppe

unread,
Dec 21, 2021, 11:54:56 AM12/21/21
to sage-devel
On Tuesday, December 21, 2021 at 2:49:11 AM UTC-8 Eric Gourgoulhon wrote:
Unless there might be a reason for it, why not replacing lines like
return r"\Bold{Q}"
by
return r"\mathbf{Q}"
in the relevant  _latex_ methods ? 

+1

 

John H Palmieri

unread,
Dec 21, 2021, 6:26:58 PM12/21/21
to sage-devel
I have no objection to this, but the purpose for using \Bold{...} was to make its behavior easily customizable, since some people might want \mathbf{...} and some might want \mathbb{...}. Are you suggesting replacing \Bold in the latex() method for the object, or keeping it but doing the redefinition as \mathbf using Python/Sphinx rather than in LaTeX?

--
John

Eric Gourgoulhon

unread,
Dec 22, 2021, 6:05:44 AM12/22/21
to sage-devel
Le mercredi 22 décembre 2021 à 00:26:58 UTC+1, John H Palmieri a écrit :
I have no objection to this, but the purpose for using \Bold{...} was to make its behavior easily customizable, since some people might want \mathbf{...} and some might want \mathbb{...}.

The customization could be performed at the Python level, instead of the LaTeX one, e.g.  something like:

def _latex_(self):
    return LatexExpr.bold_command() + r"{Q}"

with bold_command() being a static method of LatexExpr that returns the class attribute _bold_command. The latter would be initialized to r"\mathbf" and could be customized by the end user thanks to some static/class method of LatexExpr, e.g.

sage: LatexExpr.set_bold_command("mathbb")

Eric.

Matthias Koeppe

unread,
Dec 22, 2021, 12:58:03 PM12/22/21
to sage-devel
On Tuesday, December 21, 2021 at 3:26:58 PM UTC-8 John H Palmieri wrote:
I have no objection to this, but the purpose for using \Bold{...} was to make its behavior easily customizable, since some people might want \mathbf{...} and some might want \mathbb{...}. 

If we are keeping \Bold for this purpose, perhaps we should change \newcommand to \providecommand, which would fix OP's issue 
 

John H Palmieri

unread,
Dec 22, 2021, 9:16:13 PM12/22/21
to sage-devel
Sure, that sounds like a good idea.

- John

Eric Gourgoulhon

unread,
Dec 23, 2021, 5:18:05 AM12/23/21
to sage-devel
Le jeudi 23 décembre 2021 à 03:16:13 UTC+1, John H Palmieri a écrit :
Sure, that sounds like a good idea.


In the above example, I used LatexExpr  as a place holder for _bold_command, but maybe there is a better way (at least, LatexExpr has the advantage to not require any new injection in the global namespace).

Eric.
Reply all
Reply to author
Forward
0 new messages