5

Possible Duplicate:
Horizontal Spacing: double \hspace removal?

I'm trying to keep my document as abstract as possible since I'm likely to change representation of the terms I'm using on a regular basis. For this reason, I have created a number of commands similar to the following:

\newcommand{\gtDepth}{\texttt{depth}}
\newcommand{\gnInt}{\textit{int}}
\newcommand{\gtSemi}{\texttt{;}}

I can then use these commands to describe a simple grammar rule:

\gtDepth \gnInt \gtSemi

The problem is, of course, that there is no spacing between these terms. I would like to write something like the following:

\newcommand{\gspc}{\minspace{3mm}}
\newcommand{\gtDepth}{\gspc\texttt{depth}\gspc}
\newcommand{\gnInt}{\gspc\textit{int}\gspc}
\newcommand{\gtSemi}{\gspc\texttt{;}\gspc}

Specifically, I want this "minspace" construct to create space only if it is not already adjacent to that much space. For instance, I would like

a\minspace{3mm}b

to be equivalent to

a\minspace{3mm}\minspace{2mm}b

because the 3mm space is larger. It seems that \mathop provides this behavior in a very crude sort of way: things in \mathop are padded on the left and the right, but two \mathops adjacent to each other don't create twice as much space.

Any thoughts?

Thanks!

Zach
  • 51
  • 1

1 Answers1

0

Just found another stackexchange post that solves the problem. shame! It's over here: Horizontal Spacing: double \hspace removal?

Specifically, I was looking for the following. I modified it from the original post to remove the horizontal mode assertion; this makes it work in math mode for me.

\makeatletter
\def\@xaddhskip{%
\ifdim\lastskip<\@tempskipb
    \unskip
    \hskip\@tempskipb
\else
    \ifdim\@tempskipb<\z@
    \ifdim\lastskip<\z@
    \else
        \advance\@tempskipb\lastskip
        \unskip
        \hskip \@tempskipb
    \fi
    \fi
\fi}
\def\addhspace#1{%
    \ifdim \lastskip =\z@
    \hskip #1\relax
    \else
    \@tempskipb#1\relax
    \@xaddhskip
    \fi}
\makeatother

Sorry about the dupe!

Zach
  • 51
  • 1