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.
nath
package might solve the core problem, but I'm not certain. The question stands.\left
and\right
. I couldn't reproduce your problem unless I used exactly your example which I thought was just sloppy code.\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
.\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)$
.\left\right
stuff. As it currently stands, the question is really confusing.