Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question

marked as duplicate by Marco Daniel, egreg, lockstep, Andrey Vihrov, Stefan Kottwitz Mar 12 '12 at 17:34

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.

    
Do you need the objects to be equally spaced or the space between some of them should be different? –  egreg Mar 12 '12 at 17:14
    
@MarcoDaniel The question is tagged "mathmode" and \xspace doesn't work there. –  egreg Mar 12 '12 at 17:16
    
@egreg: I didn't see the tag mathmode ;-) –  Marco Daniel Mar 12 '12 at 17:20

1 Answer 1

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!

share|improve this answer
    
There's no need to be sorry, now I know about \lastskip :-) –  Andrey Vihrov Mar 12 '12 at 17:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.