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.
nathpackage might solve the core problem, but I'm not certain. The question stands. – Sean Allred Feb 10 '13 at 22:17\leftand\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\left(<stuff>\right)directly instead of\p{<stuff>}. There are a number of questions on this site about the spacing with\left\rightdelimiters instead of the direct ones, e.g. Spacing around\leftand\right. – cgnieder Feb 10 '13 at 22:38\leftand\right, which is wrong and solutions are in the post linked by @cgnieder . Second is some sort of "clever mathmode" like one thatnathpackage provides; however, I feel the need to say that the package is against my feeling of LaTeX, see e.g. Why doesn't TeX/LaTeX have reasonable defaults in certain cases? – yo' Feb 10 '13 at 22:52\def?) – Sean Allred Feb 11 '13 at 09:09\newcommandjust does replacement: as indicated in the comments above, the issue here is that you are using\leftand\rightin 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 09:09\left\rightstuff. As it currently stands, the question is really confusing. – mafp Feb 11 '13 at 10:51{..}are significant in mathematics affecting the spacing. You should write your macro in a way that takes this into account. – Andrew Swann Dec 18 '14 at 14:57