I was curious... I couldn't find this in any of the documentation of the algorithm2e and algorithmicx packages. I'm wondering if there's a way to represent objects with attributes in LaTeX. Would help a lot.
1 Answer
You can extend algorithmicx
to include, say, C-like struct
. A minimal working example:
\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\algdef{SE}% flags used internally to indicate we're defining a new block statement
[STRUCT]% new block type, not to be confused with loops or if-statements
{Struct}% "\Struct{name}" will indicate the start of the struct declaration
{EndStruct}% "\EndStruct" ends the block indent
[1]% There is one argument, which is the name of the data structure
{\textbf{struct} \textsc{#1}}% typesetting of the start of a struct
{\textbf{end struct}}% typesetting the end of the struct
\begin{document}
\begin{algorithm}
\caption*{Example of a C-like struct}
\begin{algorithmic}%[1] % uncomment for line numbers
\Struct{Person}
\State $id$ : \textsc{uuid}
\State $name$ : \textsc{String}
\EndStruct
\end{algorithmic}
\end{algorithm}
\end{document}
The only caveat is, anonymous structs aren't adequately supported in this setup.