# Pull settings from package options as variables

Sorry if it is a simple matter, but I am quite new to advanced LaTeX (before I only used preset styles and did simple things), and I couldn't find an answer after ~30 min of searching.

I want to use Harvard PhD thesis style with sidenotes package. By default Harvard PhD uses caption package to manage figure captions, but sidenotes introduces more styles (e.g. for full width figures, side captions and margin figures). I am trying to make all captions look the same. Here are my settings for caption:

\RequirePackage[labelfont={sf,bf,small},textfont={sf,small},
justification=RaggedRight,margin=0pt]{caption}


Then in order to make sidenotes captions look the same, I go through all of styles and set the same settings:

\DeclareCaptionStyle{widefigure}{labelfont={sf,bf,small},textfont={sf,small}}
\DeclareCaptionStyle{marginfigure}{labelfont={sf,bf,small},textfont={sf,small}}
\DeclareCaptionStyle{sidecaption}{labelfont={sf,bf,small},textfont={sf,small}}


But I make double work here and if I need to change one thing, I would have to change it in many places. I realize that I can define a variable which would contain style settings and then just pass it to all of these styles, but I wonder if I can instead pull the settings I already defined from caption package and pass them to sidenotes styles.

I guess in a more general form my question is: how I can pull already defined package options to use same options in another place.

• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– user31729
Oct 8, 2015 at 15:18

The options used for each package are stored in a csname of the form opt@name.sty

so for example

\RequirePackage[labelfont={sf,bf,small},textfont={sf,small},
justification=RaggedRight,margin=0pt]{caption}

\expandafter \show\csname opt@caption.sty\endcsname


shows that opt@caption.sty has the value you want.

> \opt@caption.sty=macro:
->labelfont={sf,bf,small},textfont={sf,small},justification=RaggedRight,margin=
0pt.


You can iterate through such a comma separated list of options using the standard latex \@for or any other list processing macro you need.

The caption package offers a documented [1] way to store and recall options with \captionsetup[<name>]{<options>} and \captionsetup{options=<name>}. A simple example:

\documentclass{article}
\usepackage{caption}

\begin{document}

\begin{figure}
\caption{A caption}
\end{figure}

\begin{figure}
\caption{Another caption}
\end{figure}

\end{document}


This works nested, too:

\documentclass{article}
\usepackage{caption}

\begin{document}

\begin{figure}
\caption{A caption}
\end{figure}

\begin{figure}
\captionsetup{options=test}
\caption{Another caption}
\end{figure}

\end{document}


So your code could be transformed into something like this:

\RequirePackage[justification=RaggedRight,margin=0pt]{caption}
\captionsetup[sidenotes]{labelfont={sf,bf,small},textfont={sf,small}}
...
\DeclareCaptionStyle{widefigure}{options=sidenotes}
\DeclareCaptionStyle{marginfigure}{options=sidenotes}
\DeclareCaptionStyle{sidecaption}{options=sidenotes}


[1] Yes, I have to admit that it's really poorly documented, it's only listed in the list of options in the appendix A.1.