I'm very new to TeX and am only learning it to write in MathJax on the math stackexchange. I've just discovered that I can write macros to make it easier to do repeated things, but I'm having some difficulty with how macros work.

It would appear that \def defines a macro that is delimited by strings (a series of tokens). So:

\def\foo[#1]#2{The\ first\ argument\ is\ ''#1'',\ the\ second\ one\ is\ ''#2''}

results in:

The first argument is ′′hi′′, the second one is ′′t′′here

and if I want all of 'there' as the second argument, I'd do this:


resulting in:

The first argument is ′′hi′′, the second one is ′′there′′

But is there a way to get it so that I could put braces around the entire section that contains all of the parameters, instead of having to put braces around the last parameter? Such as:

  • 1
    If this is going to be used on mathjax, this is probably not the proper place to ask. There information on this in the doc pages at mathjax.org. Generally, you should not expect mathjax to support user defined macros. It can be made to support some, but it has to be done at its configuration level, whichy you as the user cannot access. – daleif Jun 16 '16 at 11:27
  • 1
    That's just a macro with one argument: \def\foo#1{I saw `#1'} – Joseph Wright Jun 16 '16 at 11:27
  • 1
    If you are a new LaTeX user, sharelatex or overleaf might be better places to start with LaTeX as mathjax is not LaTeX, it is just a JS lib that can interpret at subpart of LaTeX – daleif Jun 16 '16 at 11:28
  • 2
    @Adrian different technologies, jut because it can understand a subset of LaTeX does not make it LaTeX. Most people can understand what x^2+y^2=z^2 but that does not make them into LaTeX interpreters. Either Install LaTeX and a decent editor on your computer, or use sharelatex/overleaf – daleif Jun 16 '16 at 11:52
  • 1
    @cfr Only if it's not also applicable to TeX: here I'm thinking it probably is OK – Joseph Wright Jun 16 '16 at 12:08

Figured it out. It is done by a level of indirection:

\def\foox[#1]#2\\{The\ first\ argument\ is\ ''#1'',\ the\ second\ one\ is\ ''#2''}

Basically, I need to specify a termination token. So, \foo will call with a single token (stuff within the {/} characters), which in turn calls \foox with a termination character of \\.

|improve this answer|||||
  • Note that this only makes sense if \foo is to be used exclusively in maths mode. – cfr Jun 16 '16 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.