0

This question already has an answer here:

When using \newcommand and the like, LaTeX seems to create a new box for the content (I'm probably observing things wrong). For example, I have \newcommand{\p}[1]{\ensuremath{\left(#1\right)}} in my preamble. When I use the command, it outputs as it might if I had accidentally inserted a \thinspace in there. Upon close observation, the paren begins where the italicized d ends (at the top of the line), thus my suspicion about the whole 'box' thing.

Obviously, the functionality I'm trying to implement is a C-preprocessor-type macro. An automatic search-and-replace. In the example, if I were to instead just type $d(x, y)$ instead of d\p{x, y}. I've been searching for a good resource on how LaTeX macros actually work (the TeXbook comes to mind, but I've yet to come across it in my reading), but the box thing makes programmatic sense if the meaning of a macro were truly based upon its use.

How would somebody implement a C-preprocessor-like macro using only (La)TeX, as opposed to \newcommand's smarty-pants-ness? The dumber, the better.

marked as duplicate by Ryan Reich, lockstep, Kurt, yo', egreg Feb 10 '13 at 23:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I should note that the nath package might solve the core problem, but I'm not certain. The question stands. – Sean Allred Feb 10 '13 at 22:17
  • Your problem doesn't seem to be the macro but the \left and \right. I couldn't reproduce your problem unless I used exactly your example which I thought was just sloppy code. – Christian Feb 10 '13 at 22:37
  • 2
    I'm sure you will observe the same thing if you insert \left(<stuff>\right) directly instead of \p{<stuff>}. There are a number of questions on this site about the spacing with \left \right delimiters instead of the direct ones, e.g. Spacing around \left and \right. – clemens Feb 10 '13 at 22:38
  • 2
    \newcommand just does replacement: as indicated in the comments above, the issue here is that you are using \left and \right in addition to the text. Try \newcommand*{\p}[1]{(#1)}: this makes $d\p{x,y}$ exactly the same as $d(x,y)$. – Joseph Wright Feb 11 '13 at 9:09
  • 1
    I would suggest asking a new question without the \left\right stuff. As it currently stands, the question is really confusing. – mafp Feb 11 '13 at 10:51

Browse other questions tagged or ask your own question.