7

I was looking for a way to beautifully display UML stereotype titles including angle brackets like you can see here:

I like

What I came up with is $\mathtt{\ll metaclass\gg}$, however, as you can see here

don't like

the brackets are too pointy (I hope you know what I mean) and the spacing between brackets and expression is too big.

Short version: Does anyone know a command for according brackets?

migrated from stackoverflow.com Feb 28 '12 at 0:36

This question came from our site for professional and enthusiast programmers.

  • Choose a different font? – meagar Feb 27 '12 at 22:15
16

Use the T1 font encoding to access \guillemotleft and \guillemotright:

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\begin{document}
$\ll$~\texttt{metaclass}~$\gg$ \par
\guillemotleft~\texttt{metaclass}~\guillemotright \par
\guillemotleft$\;$\texttt{metaclass}$\;$\guillemotright \par
\guillemotleft\,\texttt{metaclass}\,\guillemotright \par
\guillemotleft\texttt{metaclass}\guillemotright
\end{document}

The above sequence lists some spacing options: ~, $\;$, \, and {} (none).

  • If you should get a pixelated font in your output when using \usepackage[T1]{fontenc}, have a look at tex.stackexchange.com/questions/1291/…. – doncherry Feb 28 '12 at 1:25
  • 2
    As ekk said the spacing between brackets and expression is to big, I'd remove the spaces altogether or suggest using \,. – doncherry Feb 28 '12 at 1:27
  • Brilliant, exactly what I was looking for. Thank you very much! – ekk Feb 28 '12 at 11:09
  • 3
    Why not listing also the possibity of doing \texttt{<<metaclass>>}? Notice that with T1-encoded fonts the combinations << and >> produce the guillemets. – egreg Feb 28 '12 at 11:16
4

Here is a TikZ-based solution:

example

\documentclass{article}
\usepackage{tikz}
\newcommand\umlst[1]{%
  \kern.05em%
  \raisebox{-.025ex}{%
    \begin{tikzpicture}[scale=.20,line width=.15ex,join=round,cap=round]
      \draw ( 0,0) -- +(-.5,.5) -- +(0,1);
      \draw (.5,0) -- +(-.5,.5) -- +(0,1);
    \end{tikzpicture}%
  }%
  \kern.15em%
  \texttt{#1}%
  \kern.10em%
  \raisebox{-.025ex}{%
    \begin{tikzpicture}[scale=.20,line width=.15ex,join=round,cap=round]
      \draw ( 0,0) -- +(.5,.5) -- +(0,1);
      \draw (.5,0) -- +(.5,.5) -- +(0,1);
    \end{tikzpicture}
  }%
  \kern-.25em%
}

\begin{document}
\umlst{Metaclass}\par
\umlst{ObjectCreator}\par
\umlst{RegexLexerMeta}\par
\end{document}
  • 3
    I don't think it is good to use TikZ to emulate guillemets. It's an unnecessary complexity, it does not match the font style and can't be searched for/copied in the PDF. – Andrey Vihrov Feb 28 '12 at 8:51
  • 2
    I think it looks better than guillemets, but maybe that's just me. – Todd Lehman Feb 28 '12 at 9:23
1

I have come up with three solutions:

\documentclass[12pt,a4paper]{article}

\usepackage{graphicx}

% These two packages contain the symbols I hacked (a bit) to get the desired effect:

\usepackage{MnSymbol}
\usepackage{skak}

% Here the symbols are hacked (rotated and shifted as needed):

\newcommand{\gmathleft}{\rotatebox{90}{$\sqdoublefrown$}}
\newcommand{\gmathright}{\rotatebox{90}{$\sqdoublesmile$}}

\newcommand{\gleft}{\qside}
\newcommand{\gright}{\kern-0.01em\raisebox{\depth-.35pt}{\rotatebox{180}{\qside}}}

\begin{document}

% This is the first solution: just switch to typewriter font:

\texttt{<<metaclass>>}

% Here's the solution with MnSymbol:

\gmathleft\texttt{metaclass}\gmathright

% Here's the skak-based solution:

\gleft\texttt{metaclassm}\gright

\end{document}

As you can see the symbols from MnSymbol work only in math mode, while the skak symbols are text mode.

And here are the three solutions lined up:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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