# Expansion of \newcommand

The problem I am having is certainly due to my lack of understanding regarding the details of how \newcommand, \def, \edef, \let, etc. work, though I happened to encounter the problem when making use of the fnpct package.

Below is a MWE with output (the actual footnote has been suppressed to save space).

\documentclass{article}

\usepackage{fnpct}

\newcommand{\comma}{,}

\begin{document}

Hello\footnote{This is a footnote}, World!

Hello\footnote{This is another footnote}\comma again!

\end{document}


The objective is to have both cases produce the same output (well, the output of the footnote and comma anyways). (For reasons that are not given in the MWE, not making use of the \comma command is not an option.)

My understanding is that the fnpct package redefines the \footnote command to read-in what immediately follows the footnote and to type-set accordingly. In the second case, it seems as if it will read-in \comma instead of ,, and so does not properly change how it type-sets. Is there a way I can define a \comma command so that it just replaces all instances of \comma with , before 'actual' compile-time? (I have in mind something similar to the #define compiler directive in C.) Or perhaps there is some other way to accomplish the desired result?


• \setfnpct{add-punct-marks = \comma} should work as far as fnpct is concerned. The fact that there is no space after \comma unlike after , is another matter Nov 3, 2015 at 22:28
• @clemens Yes, I probably should have written \newcommand{\comma}{,\ } in the MWE as this is what I need in practice. With this together with \setfnpct{add-punct-marks=\comma} unfortunately does not achieved the desired result, as you say. Nov 3, 2015 at 22:58
• Yes, that would be more or less the same as if you wrote \comma\footnote{...} in the first place… Nov 3, 2015 at 23:04
• But that is not at all what you need in practice. If you define \comma in that way then of course you will get the output you posted because that is just what you told fnpct you wanted i.e. ,\  to be treated as punctuation it should shift to the left of a footnote. What you want is just the , shifted. The space you want after the footnote marker. You just need to protect this space as is usual with macros e.g. \footnote{note}\comma{} but... or whatever. Of course, you must remember this every time you use \comma. (But writing , is so much saner anyway, this is a minor point.)
– cfr
Nov 3, 2015 at 23:36
• Note that your C example is leading you astray, TeX is a macro expansion language not a compiler, so the analogy is only having #define . Nov 4, 2015 at 0:04

In \comma again the space is never tokenized it is simply absorbed as the terminator for the command name, if it was not there the input would be \commaagain and refer to the undefined command commaagain. This is nothing to do with comma, but just TeX syntax.

The solution is not (for many reasons) to put a space into the definition of \comma as usually it will put space in unwanted places as you show. It is better to correct the markup so that a space token is added at the point you want a space, so \comma{} again here.

With the correct input syntax, the declaration clemens suggested produces the above output.

\documentclass{article}

\usepackage{fnpct}

\newcommand{\comma}{,}