I find myself needing to define many different macros relating to variables, spaces, etc. to help define consistent font choices (\mathsf,\mathcal, normal, etc). These all essentially look like:
\newcommand{\P}{\ensuremath{\mathcal{P}}\xspace}
which lets \P be used in text/math mode, not eat spaces after it, etc. All essentially what I want out of notation definition.
I've abstracted this command system to the following constructor:
\newcommand{\makespace}[2]{\newcommand{#1}{\ensuremath{\mathcal{#2}}\xspace}}
With this macro, I'll have \makespace{\P}{P} produce the first macro I wrote, which makes all of my macro definitions more consistent/readible. I could just leave it at this, but I'll need to define multiple constructors - as an example, something like:
\newcommand{\makeconstant}[2]{\newcommand{#1}{\ensuremath{\mathsf{#2}}\xspace}}
(where \mathcal was replaced with \mathsf) would also need to be defined. So, it seems like making a constructor of constructors would be prudent, which I'd imagine would look like:
\newcommand{\makeconstructor}[2]{\newcommand{#1}[2]{\newcommand{#1'}{\ensuremath{#2{#2'}}\xspace}}}
Here's my issue - I want this two parameter macro to return a two parameter macro. How can I differentiate between #1 and #1' (which I'm sure is the incorrect notation)? What's the correct way to "keep the paramters separate" when defining a higher-order function such as this?


\xspace. (2) Use\ensuremathimproperly. (3) Define or re-define one-letter macros for math symbols instead of using more descriptive names. Note that your code would not compile with the error! LaTeX Error: Command \P already defined. Or name \end... illegal, see p.192 of the manual.– yo' Jun 21 '17 at 17:15##1, if you want to reference an argument of a command inside a command inside a command, use####1if you want to ... use########1etc. Also, do not redefine one-letter commands, they are reserved. What you do here, is redifining the macronewcommand. This is at least strange. – Michael Fraiman Jun 21 '17 at 17:24\playerin usage, for whatever reason I decided against including that here. As for not usingxspace, if I have issues with it eating spaces should I try throwing an{}on the end of whatever is causing issues, and then posting here if that doesn't work? It was introduced to me by one of my coauthors who's quite a bit more senior than me. – Mark Schultz-Wu Jun 21 '17 at 17:27templatefor it? I'm attempting to do the second, but if this would break \newcommand inadvertently that makes this all not worth it. – Mark Schultz-Wu Jun 21 '17 at 17:28xspaceandensuremathis linked. Why not$\player$? – yo' Jun 21 '17 at 17:34\newcommand, which can be considered unsafe. – Michael Fraiman Jun 21 '17 at 17:34\xspacein this example is undesirable. However, it can be very useful. For instance, intodonotes\todogobbles up the space after it. It's innocuous to redefine\todoto include an\xspacesince todo notes won't appear in the final manuscript, anyway. – JPi Jun 21 '17 at 17:37\xspaceand\ensuremathwere considered bad form, and just from a readability of code standpoint preferred\player. – Mark Schultz-Wu Jun 21 '17 at 17:39\mathsf,\mathcal, etc to wrap things in) more fluid/easily implemented, and making the section of the preamble where all this notation is actually defined slightly less verbose. – Mark Schultz-Wu Jun 21 '17 at 17:47\newcommand(and single letter names are not in general reserved) – David Carlisle Jun 21 '17 at 18:19