WeBWorK Main Forum

LaTeX macros

LaTeX macros

by Alex Jordan -
Number of replies: 2

If I have a library of problem files, there might be some custom LaTeX macro that gets used repeatedly. Say,

\newcommand{\foo}[1]{\bar{#1}}

Is there a good way to centralize such LaTeX macro definitions?

When viewing the problem in images mode, whatever is generating the png files for each image would need to access these macro definitions. The hardcopy generator would need to access them. MathJax would need to access them.

In reply to Alex Jordan

Re: LaTeX macros

by Danny Glin -
Is MathJax even capable of handling LaTeX macros? I suspect that there would be a place to put these where images mode and hardcopy mode would find them, but IIRC it would be global to the WeBWorK installation.
In reply to Danny Glin

Re: LaTeX macros

by Alex Jordan -

MathJax can handle math macros if they rely on things that MathJax can do. My example from the post works with MathJax, for example. You need to enter math mode somewhere on the page and then define the macro. Like if you do this:

$\newcommand{\foo}[1]{\bar{#1}}$

Then later on the page you can do this:

$\foo{x}$

I found a place in the code where you can add macros for image mode. There is a note there that says "stay tuned" and this will work for MathJax too. I suspect that note is like 10 years old.

You can separately add stuff to a hardcopy header for hardcopies. But it doesn't appear to recycle what you may have done for image mode.

PreTeXt makes WW problems for a math textbook, which may have its own custom LaTeX macros. So far we have gotten away with redefining the macro right before you use it. Like

${\newcommand{\foo}[1]{\bar{#1}}\bar{x}}$

MathJax does not object to redefining it this way when it has already bee defined. Images mode is atomic, so no objections there either. Hardcopy is fine because you see the scoping braces around it all stops LaTeX from seeing it as being redefined.

But this is not the same as just cerntalizing the definitions. Overall, it looks like this would have to be a new feature.