| 1 |
\documentclass{article} |
| 2 |
|
| 3 |
|
| 4 |
\usepackage[a4paper,landscape]{geometry} |
| 5 |
|
| 6 |
% preamble |
| 7 |
\usepackage{amsmath} |
| 8 |
\usepackage{amssymb} |
| 9 |
\usepackage{hyperref} |
| 10 |
\usepackage[sets,operations,nn,colors,tikz]{cora-macs} |
| 11 |
|
| 12 |
\title{The \texttt{\CORAMACSname} Package} |
| 13 |
\author{Tobias Ladner, Lukas Koller\\ |
| 14 |
TUM - Cyber-Physical Systems Group\\ |
| 15 |
\texttt{\small [email protected], [email protected]}} |
| 16 |
\date{Version: \CORAMACSversion} % Should match the version on CTAN. |
| 17 |
|
| 18 |
% update quote and verbatim environment for uniform display |
| 19 |
|
| 20 |
\AtBeginEnvironment{verbatim}{\begin{quote}\small} |
| 21 |
\AtEndEnvironment{verbatim}{\end{quote} \vspace{\baselineskip}\noindent} |
| 22 |
|
| 23 |
% show color |
| 24 |
\newcommand{\showColor}[1]{{\color{#1}$\blacksquare$}} |
| 25 |
|
| 26 |
% cleverref |
| 27 |
\usepackage{cleveref} |
| 28 |
\newcommand{\updatecrefname}[2]{\crefname{#1}{#2}{#2}\Crefname{#1}{#2}{#2}} |
| 29 |
\updatecrefname{section}{Sec.} |
| 30 |
\updatecrefname{subsection}{Sec.} |
| 31 |
\updatecrefname{figure}{Fig.} |
| 32 |
\updatecrefname{table}{Tab.} |
| 33 |
|
| 34 |
|
| 35 |
% begin document --- |
| 36 |
\begin{document} |
| 37 |
|
| 38 |
% cover page --- |
| 39 |
|
| 40 |
\maketitle |
| 41 |
|
| 42 |
% \vspace{1cm} |
| 43 |
\begin{center} |
| 44 |
\includegraphics[width=0.5\columnwidth]{./figures/coraLogo} |
| 45 |
\end{center} |
| 46 |
\vspace{1cm} |
| 47 |
|
| 48 |
\begin{center} |
| 49 |
\begin{minipage}{0.5\textwidth} |
| 50 |
\begin{abstract} |
| 51 |
The \texttt{\CORAMACSname} package provides specialized \LaTeX\ tools for researchers in cyber-physical systems. |
| 52 |
It offers comprehensive commands for mathematical set notation, operations, and other definitions. |
| 53 |
Designed to accompany the \CORA\ toolbox, the package also facilitates beautiful visualizations through TikZ figures exported from Matlab and a custom color palette. |
| 54 |
\end{abstract} |
| 55 |
\end{minipage} |
| 56 |
\end{center} |
| 57 |
|
| 58 |
\newpage |
| 59 |
|
| 60 |
% table of contents --- |
| 61 |
\tableofcontents |
| 62 |
|
| 63 |
\newpage |
| 64 |
|
| 65 |
% introduction --- |
| 66 |
|
| 67 |
\section{Introduction} |
| 68 |
The \texttt{\CORAMACSname} package is written to accompany our toolbox \CORA\footnote{\CORA: \url{https://cora.in.tum.de/}} for continuous reachability analysis. |
| 69 |
It is designed to assist with the notation of various set representation and operations often encountered in cyber-physical systems analysis. |
| 70 |
It also includes predefined color schemes and and an option to export your figures from \CORA\ to \LaTeX. |
| 71 |
|
| 72 |
\section{Installation} |
| 73 |
To install the \texttt{\CORAMACSname} package, follow these steps: |
| 74 |
\begin{enumerate} |
| 75 |
\item Place the \texttt{cora.sty} file in your working directory or in a directory where \LaTeX\ can find it (e.g., in the local \texttt{texmf} tree). |
| 76 |
\item Include the package in your \LaTeX\ document preamble with the command: |
| 77 |
\begin{verbatim} |
| 78 |
\usepackage[options]{cora-macs} |
| 79 |
\end{verbatim} |
| 80 |
\end{enumerate} |
| 81 |
\vspace{-\baselineskip} |
| 82 |
The \texttt{\CORAMACSname} package provides several options that can be passed when loading the package. These options control the inclusion of different sets of commands. |
| 83 |
|
| 84 |
\begin{itemize} |
| 85 |
\item \texttt{sets}: Enables macros for working with continuous sets (\cref{sec:sets}). |
| 86 |
\item \texttt{operations}: Enables macros for common operations in set-based computing (\cref{sec:operations}). |
| 87 |
\item \texttt{nn}: Enables macros related to neural networks (\cref{sec:nn}). |
| 88 |
\item \texttt{colors}: Defines a set of colors specific to the \texttt{\CORAMACSname} package (\cref{sec:colors}). |
| 89 |
\item \texttt{tikz}: Include your Matlab figures in \LaTeX\ for beautiful visualizations (\cref{sec:tikz}). |
| 90 |
\end{itemize} |
| 91 |
|
| 92 |
\noindent |
| 93 |
Example usage: |
| 94 |
\begin{verbatim} |
| 95 |
\usepackage[sets, operations]{cora-macs} |
| 96 |
\end{verbatim} |
| 97 |
|
| 98 |
|
| 99 |
\section{Commands and Environments} |
| 100 |
|
| 101 |
\subsection{Continuous Sets (\texttt{sets} option)} \label{sec:sets} |
| 102 |
When the \texttt{sets} option is enabled, the package provides several commands for defining and manipulating continuous sets. |
| 103 |
|
| 104 |
\begin{itemize} |
| 105 |
\item \verb|\contSet{name}|: Defines a set in calligraphic font, e.g., $\contSet{S}$. |
| 106 |
\item \verb|\shortI{a}{b}|: Defines a closed interval $\shortI{a}{b}$. For example, the command \verb|$\contSet{I}=\shortI{1}{2}$| results in $\contSet{I}=\shortI{1}{2}$. |
| 107 |
\item \verb|\defZ|: States the definition of a zonotope. For example, |
| 108 |
\begin{verbatim} |
| 109 |
\begin{equation} |
| 110 |
\contSet{Z}=\shortZ{c}{G}=\defZ |
| 111 |
\end{equation} |
| 112 |
\end{verbatim} |
| 113 |
\vspace{-2\baselineskip} |
| 114 |
results in |
| 115 |
\begin{quote} |
| 116 |
\begin{equation} |
| 117 |
\contSet{Z}=\shortZ{c}{G}=\defZ |
| 118 |
\end{equation} |
| 119 |
\end{quote} |
| 120 |
\end{itemize} |
| 121 |
|
| 122 |
Similar commands also exist for other set representations, which are accessible with its respective abbreviation. |
| 123 |
Please use the abbreviation |
| 124 |
\texttt{I} for intervals, |
| 125 |
\texttt{Z} for zonotopes, and |
| 126 |
\texttt{PZ} for polynomial zonotopes. |
| 127 |
|
| 128 |
\subsection{Operations (\texttt{operations} option)} \label{sec:operations} |
| 129 |
Enabling the \texttt{operations} option introduces a variety of operations that are useful in mathematical and cyber-physical systems contexts. |
| 130 |
|
| 131 |
\begin{itemize} |
| 132 |
\item \verb|\operator{name}{args}|: Defines a custom operator with the given name and arguments. |
| 133 |
\end{itemize} |
| 134 |
Some operations are already defined within the \CORA\ package for reference. For example, |
| 135 |
\begin{itemize} |
| 136 |
\item \verb|\opEnclose{S1}{S2}|: Computes the enclosure of two sets. |
| 137 |
\item \verb|\opIntervalEnclosure{S}|: Specifies an interval enclosure. |
| 138 |
\item \verb|\opProject{S}|: Projects a set onto a given dimension. |
| 139 |
\item \verb|\diag{matrix}|: Results the diagonal matrix of the given input. |
| 140 |
\end{itemize} |
| 141 |
|
| 142 |
The commands ensure that the surrounding parenthesis are large enough to capture the content. |
| 143 |
As this can look weird when used inline within text, one can use the option \texttt{inline} to disable the automatic scaling of the parenthesis. |
| 144 |
For example, |
| 145 |
\begin{verbatim} |
| 146 |
Given two sets $\contSet{S}$ and $\widetilde{\contSet{S}}$, |
| 147 |
the enclosure is computed using $\opEnclose{\contSet{S}}{\widetilde{\contSet{S}}}$. |
| 148 |
As this does not look very nice, |
| 149 |
let us try the \texttt{inline} option instead: $\opEnclose[inline]{\contSet{S}}{\widetilde{\contSet{S}}}$. |
| 150 |
\end{verbatim} |
| 151 |
results in |
| 152 |
\begin{quote} |
| 153 |
Given two sets $\contSet{S}$ and $\widetilde{\contSet{S}}$, |
| 154 |
the enclosure is computed using $\opEnclose{\contSet{S}}{\widetilde{\contSet{S}}}$. |
| 155 |
As this does not look very nice, |
| 156 |
let us try the \texttt{inline} option instead: $\opEnclose[inline]{\contSet{S}}{\widetilde{\contSet{S}}}$. |
| 157 |
\end{quote} |
| 158 |
|
| 159 |
\subsection{Neural Networks (\texttt{nn} option)} \label{sec:nn} |
| 160 |
The \texttt{nn} option introduces commands related to neural networks, including notation for layers, inputs, outputs, and propagations. |
| 161 |
|
| 162 |
\begin{itemize} |
| 163 |
\item \verb|\NN|: Represents the symbol for a neural network $\NN$. |
| 164 |
\item \verb|\nnLayer[name]{index}{input}|: Represents a neural network layer with a specified input. Thus \verb|$\nnLayer[LIN]{k}{x}$| results in $\nnLayer[LIN]{k}{x}$. Use \verb|\nnLayerName[name]{index}| to display the layer without explicit input. |
| 165 |
\end{itemize} |
| 166 |
One also often wants to state the propagation of an input vector or a set through the network. |
| 167 |
For example, |
| 168 |
\begin{verbatim} |
| 169 |
Given an input $\nnInput\in\R^{\numNeurons_0}$ and a neural network $\NN$, |
| 170 |
the output $\nnOutput=\NN(\nnInput)\in\R^{\numNeurons_\numLayers}$ is computed by: |
| 171 |
\begin{align} |
| 172 |
\begin{split} |
| 173 |
\nnHidden_0 &= \nnInput, \\ |
| 174 |
\nnHidden_k &= \nnLayer{k}{\nnHidden_{k-1}}, \quad k\in[\numLayers], \\ |
| 175 |
\nnOutput &= \nnHidden_\numLayers. |
| 176 |
\end{split} |
| 177 |
\end{align} |
| 178 |
\end{verbatim} |
| 179 |
results in |
| 180 |
\begin{quote} |
| 181 |
Given an input $\nnInput\in\R^{\numNeurons_0}$ and a neural network $\NN$, |
| 182 |
the output $\nnOutput=\NN(\nnInput)\in\R^{\numNeurons_\numLayers}$ is computed by: |
| 183 |
\begin{align} |
| 184 |
\begin{split} |
| 185 |
\nnHidden_0 &= \nnInput, \\ |
| 186 |
\nnHidden_k &= \nnLayer{k}{\nnHidden_{k-1}}, \quad k\in[\numLayers], \\ |
| 187 |
\nnOutput &= \nnHidden_\numLayers. |
| 188 |
\end{split} |
| 189 |
\end{align} |
| 190 |
\end{quote} |
| 191 |
|
| 192 |
Similarly, the corresponding set commands \verb|\nnInputSet|, \verb|\nnHiddenSet|, and \verb|\nnOutputSet| can be used to describe the set propagation of the input: |
| 193 |
|
| 194 |
\begin{quote} |
| 195 |
Given an input set $\nnInputSet\subset\R^{\numNeurons_0}$ and a neural network $\NN$, |
| 196 |
the output $\nnOutputSet=\NN(\nnInputSet)\subset\R^{\numNeurons_\numLayers}$ is computed by: |
| 197 |
\begin{align} |
| 198 |
\begin{split} |
| 199 |
\nnHiddenSet_0 &= \nnInputSet, \\ |
| 200 |
\nnHiddenSet_k &= \nnLayer{k}{\nnHiddenSet_{k-1}}, \quad k\in[\numLayers], \\ |
| 201 |
\nnOutputSet &= \nnHiddenSet_\numLayers. |
| 202 |
\end{split} |
| 203 |
\end{align} |
| 204 |
\end{quote} |
| 205 |
|
| 206 |
\subsection{Colors (\texttt{colors} option)} \label{sec:colors} |
| 207 |
The option \texttt{colors} define a variety of colors that can be used in your documents |
| 208 |
and is especially useful in combination with the \texttt{tikz} option (\cref{sec:tikz}). |
| 209 |
For example, these colors are available: |
| 210 |
|
| 211 |
\begin{itemize} |
| 212 |
\item \texttt{CORAcolor1}-\texttt{CORAcolor7}: Cycles through the default colors of \CORA\ |
| 213 |
(\showColor{CORAcolor1}\showColor{CORAcolor2}\showColor{CORAcolor3}\showColor{CORAcolor4}\showColor{CORAcolor5}\showColor{CORAcolor6}\showColor{CORAcolor7}). |
| 214 |
\item \texttt{CORAcolorBlue}, \texttt{CORAcolorRed}, \ldots: Specifies default color values used in \CORA\ |
| 215 |
(\showColor{CORAcolorBlue}\showColor{CORAcolorRed}\showColor{CORAcolorYellow}\showColor{CORAcolorPurple}\showColor{CORAcolorGreen}\showColor{CORAcolorLightBlue}\showColor{CORAcolorDarkRed}). |
| 216 |
\item \texttt{CORAcolorReachSet}: A predefined color for reachable sets (\showColor{CORAcolorReachSet}). |
| 217 |
If two reachable sets are compared in one plot, one case use \texttt{CORAcolorReachSet2} (\showColor{CORAcolorReachSet2}). |
| 218 |
The initial set and simulations can be plotted with \texttt{CORAcolorInitialSet} (\showColor{CORAcolorInitialSet}) and \texttt{CORAcolorSimulations} (\showColor{CORAcolorSimulations}), respectively. |
| 219 |
\item \texttt{CORAcolorSafe}: A predefined color for safe sets (\showColor{CORAcolorSafe}). |
| 220 |
\item \texttt{CORAcolorUnsafe}: A predefined color for unsafe sets (\showColor{CORAcolorUnsafe}). |
| 221 |
As this color can be intimidating when used at large scale, there is also the \texttt{CORAcolorUnsafeLight} color (\showColor{CORAcolorUnsafeLight}). |
| 222 |
|
| 223 |
\item \texttt{TUMblue}: TUM corporate blue color (\showColor{TUMblue}). |
| 224 |
\end{itemize} |
| 225 |
|
| 226 |
To plot sets in the default style of CORA, you can use the \texttt{plot filled} pgf key to automatically set the edge color and face color: |
| 227 |
|
| 228 |
\begin{verbatim} |
| 229 |
\addplot [plot filled=CORAcolorBlue] |
| 230 |
\end{verbatim} |
| 231 |
|
| 232 |
\subsection{TikZ Figures (\texttt{tikz} option)}\label{sec:tikz} |
| 233 |
|
| 234 |
Visualizations are a crucial part in communicating your scientific findings. |
| 235 |
We found that the best option to do so is using TikZ\footnote{Manual: \url{http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}}\footnote{Example: \url{https://www.overleaf.com/learn/latex/TikZ_package}} figures. |
| 236 |
The \texttt{tikz} option provides you with a wide variety of useful functionality. |
| 237 |
|
| 238 |
\subsubsection{Introduction} |
| 239 |
|
| 240 |
Let us create a small TikZ graphic in a file \texttt{./figures/mytikzfigure.tikz}: |
| 241 |
|
| 242 |
\begin{verbatim} |
| 243 |
\begin{tikzpicture} |
| 244 |
\draw[CORAcolorBlue] (-6,0) rectangle (-4,2); |
| 245 |
\draw[CORAcolorRed] (-2,1) circle (1cm); |
| 246 |
\draw[CORAcolorYellow] (0,0) -- (0,1) -- (1,2) -- (2,2) -- (2,1) -- (1,0) -- (0,0); |
| 247 |
\end{tikzpicture} |
| 248 |
\end{verbatim} |
| 249 |
|
| 250 |
To include the figure in the main document, please use the following commands: |
| 251 |
\begin{verbatim} |
| 252 |
\begin{figure} |
| 253 |
\centering |
| 254 |
\includetikz{./figures/mytikzfigure} |
| 255 |
\caption{My first TikZ figure.} |
| 256 |
\label{fig:mytikzfigure} |
| 257 |
\end{figure} |
| 258 |
\end{verbatim} |
| 259 |
|
| 260 |
To compile the document, you need to enable shell-escape\footnote{Shell-escape: \url{https://tex.stackexchange.com/questions/598818/how-can-i-enable-shell-escape}}. |
| 261 |
Usually, this is achieved by adding the compiler argument \texttt{--shell-escape} when compiling the document. |
| 262 |
For example, run \texttt{pdflatex --shell-escape main.tex}. |
| 263 |
The code above then results in \cref{fig:mytikzfigure} within your document. |
| 264 |
\begin{figure}[h!] |
| 265 |
\centering |
| 266 |
\includetikz{./figures/mytikzfigure} |
| 267 |
\caption{My first TikZ figure.} |
| 268 |
\label{fig:mytikzfigure} |
| 269 |
\end{figure} |
| 270 |
|
| 271 |
Shell-escape allows \LaTeX\ to \emph{externalize} the TikZ figures, |
| 272 |
i.e., creating a stand-alone PDF file which it can use in future compilations to speed up the compilation. |
| 273 |
By default the externalization is disabled. You can enable the externalization by default by calling the following command in the preamble: \verb|\CORAexternalizeFiguresByDefault|. |
| 274 |
The PDF file is located at \texttt{./figures/externalize/figures/mytikzfigure.pdf}, |
| 275 |
which you can also use outside of your \LaTeX\ document. |
| 276 |
In case something is wrong with your TikZ figures, you can also find a log file within the same directory. |
| 277 |
|
| 278 |
After the pdf is created, you can also include the respective pdf directly by setting the \texttt{usepdf} flag: |
| 279 |
\begin{verbatim} |
| 280 |
\begin{figure} |
| 281 |
\centering |
| 282 |
\includetikz[usepdf]{./figures/mytikzfigure} |
| 283 |
\caption{My first TikZ figure.} |
| 284 |
\end{figure} |
| 285 |
\end{verbatim} |
| 286 |
If you cannot enable shell-escape but have access to the externalized PDF files, |
| 287 |
you can use \verb|\CORAexternalizeusepdf| to directly use the PDF files instead of the TikZ files. |
| 288 |
Please note that this is done for all TikZ files. |
| 289 |
If you only want to use the pdf for individual files, use the \texttt{usepdf} flag as described above. |
| 290 |
|
| 291 |
If you want to externalize only individual TikZ images, you can use the \texttt{export} option: |
| 292 |
\begin{verbatim} |
| 293 |
\begin{figure} |
| 294 |
\centering |
| 295 |
\includetikz[export]{./figures/mytikzfigure} |
| 296 |
\caption{My first TikZ figure.} |
| 297 |
\end{figure} |
| 298 |
\end{verbatim} |
| 299 |
Similarly, if you do not want to externalize individual TikZ images, you can use the \texttt{noexport} option: |
| 300 |
\begin{verbatim} |
| 301 |
\begin{figure} |
| 302 |
\centering |
| 303 |
\includetikz[noexport]{./figures/mytikzfigure} |
| 304 |
\caption{My first TikZ figure.} |
| 305 |
\end{figure} |
| 306 |
\end{verbatim} |
| 307 |
|
| 308 |
\subsubsection{Exporting Figures from Matlab/\CORA} |
| 309 |
As this package is designed to assist you with our toolbox \CORA\footnote{\CORA: \url{https://cora.in.tum.de/}}, |
| 310 |
we also provide an option to export your Matlab figures to \LaTeX\ named \texttt{matlab2tikz}\footnote{matlab2tikz: \url{https://gitlab.lrz.de/cora/matlab2tikz}, fork from: \url{https://github.com/matlab2tikz/matlab2tikz}}. |
| 311 |
The resulting figures are then in TikZ/PGF\footnote{TikZ/PGF Manual: \url{http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}} format. |
| 312 |
Please ask for access if you want to use this option. |
| 313 |
|
| 314 |
After clone the repository and adding it to the Matlab path, |
| 315 |
you can convert your current open figure with |
| 316 |
\begin{verbatim} |
| 317 |
path = 'mymatlabfigure.fig'; |
| 318 |
savefig(path); |
| 319 |
autoConvertToTikz(path); |
| 320 |
\end{verbatim} |
| 321 |
which makes use of the underlying \texttt{matlab2tikz} function by setting some optimization options. Type |
| 322 |
\begin{verbatim} |
| 323 |
open autoConvertToTikz |
| 324 |
\end{verbatim} |
| 325 |
for details. |
| 326 |
After successful conversion, you should find a file \texttt{mymatlabfigure.tikz} in the current directory. |
| 327 |
This figure can then be moved to your \LaTeX\ project and added to your document as above: |
| 328 |
\begin{verbatim} |
| 329 |
\begin{figure} |
| 330 |
\centering |
| 331 |
\includetikz{./figures/mymatlabfigure} |
| 332 |
\caption{My first Matlab figure.} |
| 333 |
\label{fig:mymatlabfigure} |
| 334 |
\end{figure} |
| 335 |
\end{verbatim} |
| 336 |
which results in \cref{fig:mymatlabfigure}. |
| 337 |
\begin{figure}[h!] |
| 338 |
\centering |
| 339 |
\includetikz{./figures/mymatlabfigure} |
| 340 |
\caption{My first Matlab figure.} |
| 341 |
\label{fig:mymatlabfigure} |
| 342 |
\end{figure} |
| 343 |
|
| 344 |
If you have a figure with multiple subplots, \texttt{matlab2tikz} creates multiple TikZ files: |
| 345 |
The main TikZ file contains all settings and plotting options of your figure, |
| 346 |
the content of each subplot is exported in a separate file, |
| 347 |
and an additional file for the legend of your figure is generated. |
| 348 |
Such a figure can be added as above but you have to specify the path to the TikZ files within the main TikZ file, e.g., |
| 349 |
\begin{verbatim} |
| 350 |
\def\basepath{./figures/} |
| 351 |
\end{verbatim} |
| 352 |
An example figure is visible in \cref{fig:mymatlabgroupfigure}. |
| 353 |
|
| 354 |
Your figures can then be customized as required, e.g., adapting the color (also see \cref{sec:colors}), adding labels of the x- and y-axis, and adapt the legend entries. |
| 355 |
Please visit the TikZ/PGF manual\footnote{TikZ/PGF Manual: \url{http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}} for details. |
| 356 |
We have also found that large language models like ChatGPT work surprisingly well with TikZ, |
| 357 |
so you might want to consult them about specific requests. |
| 358 |
|
| 359 |
\begin{figure}[h!] |
| 360 |
\centering |
| 361 |
\includetikz{./figures/mymatlabgroupfigure} |
| 362 |
\caption{My first Matlab figure with multiple subplots.} |
| 363 |
\label{fig:mymatlabgroupfigure} |
| 364 |
\end{figure} |
| 365 |
|
| 366 |
\subsubsection{TikZ, Git, and Overleaf} |
| 367 |
If you synchronize your \LaTeX\ document with git, |
| 368 |
we recommend you to also synchronize the externalized PDF files. |
| 369 |
You can add \texttt{*.log}, \texttt{*.dpth}, and \texttt{*.md5} to your \texttt{.gitignore} and only need to synchronize the PDF itself. |
| 370 |
|
| 371 |
If you want to use this TikZ figures in Overleaf\footnote{Overleaf: \url{https://overleaf.com/}}, |
| 372 |
we recommend you to build the figures locally and upload the PDF files into the correct folder. |
| 373 |
While you can also externalize the figures directly in Overleaf\footnote{Overleaf and TikZ: \url{https://tex.stackexchange.com/questions/596557/overleaf-cache-not-working-properly-with-tikzexternalize-and-include}}, |
| 374 |
this has several disadvantages, e.g., having to rebuild all figures when re-opening the document after some time. |
| 375 |
Note: TUM students can also use the TUM instance of Overleaf, which is called ShareLaTeX\footnote{ShareLaTeX: \url{https://sharelatex.tum.de/}}. |
| 376 |
There, they can create a git repository out of the project (Menu $\textrangle$ Git) and clone the repository to interact with the project locally. |
| 377 |
|
| 378 |
\subsubsection{Animated Tikz Figures in Presentations} |
| 379 |
Generally, you can use the same commands as above to include your TikZ figures in presentations\footnote{Document class \texttt{beamer}: \url{https://www.overleaf.com/learn/latex/Beamer}}. |
| 380 |
However, this package also provides some nice commands to animate your figures. |
| 381 |
We provide an example presentation showcasing these options along with the respective animated TikZ figures in \texttt{./examples/presentation.tex}. |
| 382 |
|
| 383 |
To enable animations, please specify the number of overlays of the current frame and add the \texttt{animate} option when including a TikZ figure: |
| 384 |
\begin{verbatim} |
| 385 |
\begin{frame}<1-4>{Introduction to \CORA} |
| 386 |
\CORA provides you with a wide range of plotting capabilities: |
| 387 |
\begin{figure} |
| 388 |
\includetikz[animate]{./figures/mymatlabfigure} |
| 389 |
\end{figure} |
| 390 |
\end{frame} |
| 391 |
\end{verbatim} |
| 392 |
You can then animate a plot using the \texttt{visible on}/\texttt{invisible on} options. For example, |
| 393 |
\begin{verbatim} |
| 394 |
\addplot [color=CORAcolor1, visible on=<2->] |
| 395 |
\end{verbatim} |
| 396 |
only shows the respective plot from the second overlay onwards. |
| 397 |
You can also use \verb|\only<>{}| to display certain text only on certain slides. |
| 398 |
For example |
| 399 |
\begin{verbatim} |
| 400 |
\only<1|handout:0>{My secret message.} |
| 401 |
\end{verbatim} |
| 402 |
only shows this text on the first overlay of the current frame but not if the document is set to \texttt{handout} mode\footnote{Beamer \texttt{handout} mode: \url{https://tex.stackexchange.com/questions/473485/latex-beamer-handout-beamer-mode-with-overlays}}. |
| 403 |
This option can also be used inside TikZ figures, e.g., to specify node labels depending on the current overlay. |
| 404 |
|
| 405 |
Mode advances animations can be achieved using the \texttt{alt} option, |
| 406 |
which allows to alter the plot style depending on the current overlay (if-then-else). |
| 407 |
For example, |
| 408 |
\begin{verbatim} |
| 409 |
\nextgroupplot[..., plotstyle1/.append style={alt=<1>{fill=CORAcolor1}{fill=none}}] |
| 410 |
\end{verbatim} |
| 411 |
fills all objects with \texttt{plotstyle1} in the first overlay but not in subsequent overlays. |
| 412 |
This changes the style for each subplot. Alternatively, the style can also be animated across all subplots. |
| 413 |
\begin{verbatim} |
| 414 |
\pgfplotsset{ |
| 415 |
plotstyle1/.style={...,alt=<2->{}{draw=none},alt=<2|handout:0>{fill=CORAcolor1!20}{}} |
| 416 |
} |
| 417 |
\end{verbatim} |
| 418 |
|
| 419 |
\subsubsection{Drawing Neural Networks} |
| 420 |
|
| 421 |
This package also provides an option to draw neural networks: |
| 422 |
\begin{verbatim} |
| 423 |
\begin{tikzpicture} |
| 424 |
% draw network |
| 425 |
\pic[] at (0,0) { nn={3}{2,5,5,2}{0.15cm}{0.02cm} }; |
| 426 |
|
| 427 |
% label the third node in the second layer with a '#' |
| 428 |
\node also [neuron label={\#}] (l2-3); |
| 429 |
\end{tikzpicture} |
| 430 |
\end{verbatim} |
| 431 |
which results in \cref{fig:neural-network}. |
| 432 |
|
| 433 |
\begin{figure}[h!] |
| 434 |
\centering |
| 435 |
\includetikz{./figures/neural-network} |
| 436 |
\caption{Example neural network with a neuron label.} |
| 437 |
\label{fig:neural-network} |
| 438 |
\end{figure} |
| 439 |
|
| 440 |
\section{Examples} |
| 441 |
Here are some examples demonstrating how to use the commands from the \texttt{\CORAMACSname} package. |
| 442 |
We recommend to define \LaTeX\ commands for each variable you use in your document. |
| 443 |
|
| 444 |
\subsection{Set Notation} |
| 445 |
For example, to denote the initial set, you can define |
| 446 |
\newcommand{\initialSet}{\contSet{X}_0} |
| 447 |
\begin{verbatim} |
| 448 |
\newcommand{\initialSet}{\contSet{X}_0} |
| 449 |
\end{verbatim} |
| 450 |
within your preamble and then use it within your document as follows: |
| 451 |
\begin{verbatim} |
| 452 |
\begin{equation} |
| 453 |
\initialSet = \shortZ{c}{G}. |
| 454 |
\end{equation} |
| 455 |
\end{verbatim} |
| 456 |
which results in |
| 457 |
\begin{quote} |
| 458 |
\begin{equation} |
| 459 |
\initialSet = \shortZ{c}{G}. |
| 460 |
\end{equation} |
| 461 |
\end{quote} |
| 462 |
|
| 463 |
\subsection{Operations} |
| 464 |
To define a new operation, simply add |
| 465 |
\newcommand{\opLinComb}[3][]{\operatortt[#1]{linComb}{#2,#3}} |
| 466 |
\begin{verbatim} |
| 467 |
\newcommand{\opLinComb}[3][]{\operatortt[#1]{linComb}{#2,#3}} |
| 468 |
\end{verbatim} |
| 469 |
to your preamble and then use it within your document as follows: |
| 470 |
\begin{verbatim} |
| 471 |
Given two sets $\contSet{S}_1,\contSet{S}_2\subset\R^n$, their linear combination is defined as |
| 472 |
\begin{equation} |
| 473 |
\opLinComb{\contSet{S}_1}{\contSet{S}_2} \coloneqq |
| 474 |
\left\{ \lambda s_1 + (1-\lambda s_2)\ \middle|\ |
| 475 |
s_1\in\contSet{S}_1,\,s_2\in\contSet{S}_2,\,\lambda \in[0,1] \right\}. |
| 476 |
\end{equation} |
| 477 |
\end{verbatim} |
| 478 |
which results in |
| 479 |
\begin{quote} |
| 480 |
Given two sets $\contSet{S}_1,\contSet{S}_2\subset\R^n$, the linear combination is defined as |
| 481 |
\begin{equation} |
| 482 |
\opLinComb{\contSet{S}_1}{\contSet{S}_2} \coloneqq |
| 483 |
\left\{ \lambda s_1 + (1-\lambda s_2)\ \middle|\ |
| 484 |
s_1\in\contSet{S}_1,\,s_2\in\contSet{S}_2,\,\lambda \in[0,1] \right\}. |
| 485 |
\end{equation} |
| 486 |
\end{quote} |
| 487 |
|
| 488 |
\subsection{Neural Networks} |
| 489 |
To specify a specific network layer, one can write |
| 490 |
\begin{verbatim} |
| 491 |
A linear layer is defined as |
| 492 |
\begin{equation} |
| 493 |
\nnLayer[LIN]{k}{\nnHidden_{k-1}} \coloneqq W\nnHidden_{k-1} + b, |
| 494 |
\quad W\in\R^{\numNeurons_{k}\times\numNeurons_{k-1}},\, b\in\R^{\numNeurons_k}. |
| 495 |
\end{equation} |
| 496 |
\end{verbatim} |
| 497 |
which results in |
| 498 |
\begin{quote} |
| 499 |
A linear layer is defined as |
| 500 |
\begin{equation} |
| 501 |
\nnLayer[LIN]{k}{\nnHidden_{k-1}} \coloneqq W\nnHidden_{k-1} + b, |
| 502 |
\quad W\in\R^{\numNeurons_{k}\times\numNeurons_{k-1}},\, b\in\R^{\numNeurons_k}. |
| 503 |
\end{equation} |
| 504 |
\end{quote} |
| 505 |
|
| 506 |
\section{Concluding Remarks} |
| 507 |
The \texttt{\CORAMACSname} package offers a comprehensive set of tools for researchers working in cyber-physical systems. |
| 508 |
By providing a consistent notation and color scheme, this package simplifies the process of documenting complex mathematical objects and operations. |
| 509 |
We very much encourage you to extend the functionality of this package and define your own commands for everything you need to improve the consistency throughout your \LaTeX\ document. |
| 510 |
If you have suggestions to include certain commands in this package, please contact us and we are happy to discuss them! |
| 511 |
For more information, visit the \href{https://www.ce.cit.tum.de/cps}{TUM CPS Group website}. |
| 512 |
\end{document} |