3

I'm defining it like this for myself:

\newcommand\nothing[1]{#1}

Maybe the same already exists in LaTeX and I can just use it?

PS. The purpose of this is to highlight certain parts of the .tex document for another post-processor (spell checker). In reality, my command's name is \nospellcheck.

yegor256
  • 12,021
  • 1
    There are \@firstofone and \@iden but of course with @ in their name. No user macros AFAIK. – campa Aug 23 '21 at 09:07
  • 3
    For which purpose do you want it or need it? – MS-SPO Aug 23 '21 at 09:25
  • 1
    \relax can be a do-nothing command. \empty expands to nothing. Adapting to your syntax, \newcommand\nothing{} takes no argument. The command you present does something...it absorbs an argument and echoes it. – Steven B. Segletes Aug 23 '21 at 09:29
  • How about \newcommand\donothing[1]{Donald Trump}? – Gaussler Aug 23 '21 at 12:29
  • 1
    Your \donothing command just echos the following argument. Is that what you want? Then \relax should do the job. PS: it takes no arguments so it does nothing. Do you really want it to gobble the argument? – Herb Schulz Aug 23 '21 at 12:49
  • What does "do nothing" mean? Your \donothing-command does not nothing: It strips the outermost level of matching curly braces if present. Both \donothing a and \donothing {a} yield a, without surrounding curly braces. Your \donothing-command is the same as \@firstofone and it could probably be called "just-spit-out--the-grabbed-argument"-command. \empty/\@empty could be called the "grab-no-argument-and-expand-to-nothing"-command. \@gobble could be called the "gobble-an-argument"-command. \relax could be called the "go-to-TeX's-stomach-but-trigger-no-action-there"-command. – Ulrich Diez Oct 07 '21 at 13:24

1 Answers1

3

Any time you absorb an argument using the standard approach, you are potentially losing information...for example, a leading space before the absorbed argument. Another example is if the argument absorbed is a single token, you won't know if it originally had braces on it or not. As a result of these uncertainties, I tend not to consider argument absorption as a "do nothing" command.

In the MWE below, the active-Q is set to the OP's definition of \nothing. It is employed twice in the 2nd line. In the first instance, one loses the space because of argument absorption. In the 2nd instance, one loses the braces around a.

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand\nothing[1]{#1}
\begin{document}
\catcode`\Q=\active

\letQ\nothing

a b\detokenize{{a}}

aQ b\detokenize\expandafter{Q{a}} \end{document}

enter image description here

A better "do nothing" command would be

\newcommand\nothing{}

or, equivalently,

\let\nothing\empty

However, even that is not foolproof. Any new token introduced, even \empty, can interfere if it becomes the target of an expansion or absorption.

Here's such an example where the introduction of the simplified \nothing still changes the result (though, in this case, the \nothing improves the result):

\documentclass{article}
\usepackage[T1]{fontenc}
\let\nothing\empty
\begin{document}
\def\z|#1|{\detokenize\expandafter{#1}}

\z|{abc}|

\z|\nothing{abc}| \end{document}

enter image description here

Note: this exact situation was a bug I just discovered yesterday in my tokcycle package when text is escaped from the cycle when placed between | delimiters. It lost the braces if the escaped text was a single brace group, in the manner shown in the first line above. My fix, which I am about to submit to CTAN, amounts to using the technique with \empty, shown on the second line, which will retain those braces.

  • I never imagined a question about an identity command would lead to such a long, philosophical elaboration. ;-) – Gaussler Aug 25 '21 at 14:13
  • @Gaussler writing tokcycle, which tries to absorb an input stream token by token without losing information, gave me a huge respect and awareness for these sort of unanticipated interactions. Even so, it is certainly not without pathological cases, especially when you throw in active characters, catcode changes, cat-6 tokens, implicit grouping, implicit spaces, etc. The most interesting anomaly is the active token whose charcode is no longer active! – Steven B. Segletes Aug 25 '21 at 14:43
  • @Gaussler Now make it an "active implicit space token whose charcode is no longer active" and you can begin to appreciate the difficulties. – Steven B. Segletes Aug 25 '21 at 14:49
  • I certainly do appreciate “do nothing” commands. In fact, in preparation for the age of tagged PDFs and semantic math markup, I have started using a command \invmult for an invisible multiplication symbol. It’s not quite \newcommand\invmult{}, but it’s close to that. ;-) – Gaussler Aug 26 '21 at 11:13
  • @Gaussler Perhaps you mean the "discretionary multiplication" macro, \let\invmult\* – Steven B. Segletes Aug 26 '21 at 11:17
  • As far as I remember, \* becomes \times at line breaks, not \cdot. Research-level mathematics never uses \times for ordinary multiplication. Plus, I would never want it to become visible at line breaks. (And in reality, I used a semantic-based construction. This also allows me to use stripsemantex for later removing it from my document when preparing it for publication. Also, I program it so that it can also be used as an n-ary operation, so that e.g. \invmult{\va,\vb,...,\vz} prints ab⋯z.) ;-) – Gaussler Aug 26 '21 at 11:24
  • Well, there you go @Gaussler...if "research-level mathematics never uses \times for ordinary multiplication", then sounds like it's time to redefine \* to suit your needs. It takes fewer keystrokes than \invmult. – Steven B. Segletes Aug 26 '21 at 11:28
  • I actually did plan to ask in here about how to do that, but never pulled myself together. But again, I can’t think of a situation where I would be using such a “maybe \cdot” command. The number of keystrokes has never really been a problem to me . I can type “\invmult” in about 1.2 seconds. ;-) – Gaussler Aug 26 '21 at 11:30