5

I would like to create a postfix unary operator that normally leaves \medmuskip between the operand and postfix operator. It's easy enough to do this using, for example,

\newcommand*{\true}{\mskip\medmuskip\mathsf{true}} 

so that x$A \true x$x yields enter image description here

However, the extra twist is that I would like to use a group to suppress the spacing, just as is possible for binary operators (such as \otimes). In other words, x$A{\true}x$x should yield enter image description here. Bonus points for making x$\true$x (note the absence of {}) yield enter image description here.

Here is a skeleton to play with:

\documentclass{article} \usepackage{amsmath} \usepackage{amssymb} \newcommand*{\true}{\mskip\medmuskip\mathsf{true}} \begin{document} \begin{tabular}{ll} \verb#x$A \true x$x# & x$A \true x$x \\ \verb#x$A{\true}x$x# & x$A{\true}x$x \\ \verb#x$\true$x# & x$\true$x \end{tabular} \end{document} 
3
  • 1
    What do you think to use \DeclareMathOperator{\true}{true} or \DeclareMathOperator{\true}{\medspace true}. Commented Jan 11, 2013 at 22:07
  • @Sigur This inserts \thinmuskip, not \medmuskip Commented Jan 11, 2013 at 22:23
  • Yes, this is almost, but not quite, what I am looking for. If I use \DeclareMathOperator and write x$A \true x$x, I get a space after the operator, i.e., it acts as a binary operator. I've edited my question to clarify what I am after. Commented Jan 11, 2013 at 22:23

1 Answer 1

8

enter image description here

\documentclass{article} \usepackage{amsmath} \usepackage{amssymb} \newcommand*{\true}{\relax\ifnum\lastnodetype>0 \mskip\medmuskip\fi\mathsf{true}} \begin{document} \begin{tabular}{ll} \verb#x$A \true$x# & x$A \true$x \\ \verb#x$A{\true}$x# & x$A{\true}$x \\ \verb#x$\true$x# & x$\true$x \end{tabular} \end{document} 
4
  • Thanks, this does just what I am looking for! I'd like to understand how this solution works, though. Could you add an explanation of \lastnodetype (or point me to a reference) and why \relax is needed? Commented Jan 11, 2013 at 22:29
  • it's an etex extension (so texdoc etex page 7 has the details) it tells you something about the previous thing on the curent list {} starts a new list and if you are at the start of a list it is -1 it would be 11 for glue or 15 for a math node etc you need \relax (or make \true robust) to stop bad expansion in a table cell when tex is looking for \omit (\multicolumn) Commented Jan 11, 2013 at 22:34
  • @HenryDeYoung Watch out that $\left(\true\right) will insert the space, but I think that you don't need such a strange concoction. Other than this, it's a very clever answer and I don't think one can do better (without LuaTeX). Commented Jan 11, 2013 at 22:42
  • Yes You need explicit {} as in $\left({\true}\right) to zap the space unfortunately almost all math constructs show as 15 so you can not distinguish the mathopen form \left( Commented Jan 11, 2013 at 22:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.