0

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.

Sean Allred
  • 27,421
  • 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. – cgnieder Feb 10 '13 at 22:38
  • You are clearly speaking about two different things: First is spacing around \left and \right, which is wrong and solutions are in the post linked by @cgnieder . Second is some sort of "clever mathmode" like one that nath package 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
  • Thanks for the link to the other answer -- that fixed the problem for now. However, I really would appreciate a way to have much dumber macros than (La)TeX seems to provide. (On second thought, is the dumb macro I'm looking for \def?) – Sean Allred Feb 11 '13 at 09:09
  • 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 09: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
  • Also brackets {..} 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
  • I ended up stumbling across a 'solution' for this, answered here: http://tex.stackexchange.com/a/262431/17423 – Sean Allred Aug 21 '15 at 14:27

0 Answers0