Skip to content

Instantly share code, notes, and snippets.

@godbyk
Created March 21, 2011 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godbyk/879126 to your computer and use it in GitHub Desktop.
Save godbyk/879126 to your computer and use it in GitHub Desktop.
Environment for typesetting UML use cases
%
% A simple description-like environment that can be used for writing UML use
% cases.
%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{usecase}[2011/03/21 v0.1 A usecase environment.]
%
% Required so we can use inline arithmetic in the usecase environment
% defition. Could be removed and the code below could use \addtolength
% instead.
%
\RequirePackage{calc}
%
% Used in the usecase environment to ensure that the \usecaselabelwidth has
% been set.
%
\RequirePackage{ifthen}
%
% The style of the labels
%
\newcommand{\usecaselabelstyle}{%
\normalfont\bfseries
}
%
% Used below to set the label width to the width of the longest label
%
\newlength{\usecaselabelwidth}
\setlength{\usecaselabelwidth}{0pt}
\newcommand{\maxusecaselabel}[1]{%
\settowidth{\usecaselabelwidth}{\usecaselabelstyle #1}%
}
%
% The definition of the usecase environment -- where all the 'magic' happens
%
\newenvironment{usecase}{%
\begin{list}{}{%
\ifthenelse{\lengthtest{\usecaselabelwidth=0pt}}{%
\PackageError{usecase}{You must call \string\maxusecaselabel}{%
You should call \string\maxusecaselabel{LongestUseCaseLabel}, where
\MessageBreak
LongestUseCaseLabel is the longest label used in your usecase
environment.
}%
}{}%
\renewcommand{\makelabel}[1]{%
\usecaselabelstyle ##1%
\hfil
}%
\setlength{\labelwidth}{\usecaselabelwidth}%
\setlength{\leftmargin}{\labelwidth+\labelsep}%
}%
}{%
\end{list}%
}
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment