# Outer join symbols

In a previous post entitled "Symbols for Outer Joins" a solution was given to produce outer join symbols.

However, this solution generates an error when, e.g., $R \leftouterjoin S$ is used in a caption.

Any solution for this ?

\documentclass[a4paper,10pt]{article}

\usepackage{latexsym}

% Definition of outer joins

\def\ojoin{\setbox0=\hbox{$\Join$}
\rule[0.10ex]{.3em}{.4pt}\llap{\rule[1.40ex]{.3em}{.4pt}}}
\def\leftouterjoin{\mathrel{\ojoin\mkern-6.5mu\Join}}
\def\rightouterjoin{\mathrel{\Join\mkern-6.5mu\ojoin}}
\def\fullouterjoin{\mathrel{\ojoin\mkern-6.5mu\Join\mkern-6.5mu\ojoin}}

\begin{document}

The outer join symbols work great in text: $R\rightouterjoin S$, $R\leftouterjoin S$, $R\fullouterjoin S$.
However, it generates the error \verb+Argument of \@caption has an extra }.+ when used in captions.

\begin{figure}
\centering
This a figure
\caption{$R\rightouterjoin S$}
\end{figure}

\end{document}

• try inserting \protect just before that command. – barbara beeton Oct 19 '13 at 14:48
• Alas it does not solve the problem when I put \caption{\protect $R\rightouterjoin S$} – Esteban Zimanyi Oct 19 '13 at 15:02
• It needs to precede your command: \caption{$R\protect\rightouterjoin S$} – Pedro Oct 19 '13 at 15:10
• i meant \protect\rightouterjoin. the \protect must be immediately before the command (and it's always a command) that is causing the trouble. or you could define the command as "robust"; check this forum for how to do that. – barbara beeton Oct 19 '13 at 15:11

If you define \ojoin to be robust then there is no problem:

\documentclass[a4paper,10pt]{article}

\usepackage{latexsym}

% Definition of outer joins

\DeclareRobustCommand{\ojoin}{\rule[0.10ex]{.3em}{.4pt}\llap{\rule[1.40ex]{.3em}{.4pt}}}
\newcommand{\leftouterjoin}{\mathrel{\ojoin\mkern-6.5mu\Join}}
\newcommand{\rightouterjoin}{\mathrel{\Join\mkern-6.5mu\ojoin}}
\newcommand{\fullouterjoin}{\mathrel{\ojoin\mkern-6.5mu\Join\mkern-6.5mu\ojoin}}

\begin{document}
\show\ojoin
The outer join symbols work great in text: $R\rightouterjoin S$, $R\leftouterjoin S$, $R\fullouterjoin S$.
However, it generates the error \verb+Argument of \@caption has an extra }.+ when used in captions.

\begin{figure}
\centering
This a figure
\caption{$R\rightouterjoin S$}
\end{figure}

\end{document}


The problem is that \rule is a fragile command in LaTeX and needs to either be \protected or make robust for use in captions. Cf. What is the difference between Fragile and Robust commands?