Quantcast
Channel: Pass a command as optional argument of environment - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 3

Pass a command as optional argument of environment

$
0
0

Sorry for the beginner question, but I'd like to know if there is a robust way to do what the title says. The following MWE

\documentclass{book}\usepackage[demo]{graphicx}\newcommand{\myoptions}{h!tb}\begin{document}\begin{figure}[\myoptions]  \centering  \includegraphics[width=0.5\textwidth]{whatever}  \caption[Short caption citing something]{Long caption.}  \label{fig:whatever}\end{figure}\end{document}

gives the error ! LaTeX Error: Unknown float option '\'..

Actually I found a workaround (in my actual document the \figure environment is used by a new command that takes many parameters needed to define a figure and puts them inside \figure), but it gives problems with \cite command inside short caption, that's why I'm looking for a robust solution.

SOLUTION

Here is the solution to this question, that was given as a comment to the accepted answer:

\documentclass{book}\usepackage[demo]{graphicx}\newcommand{\myoptions}{h!tb}\def\tmp#1{\begin{figure}[#1]}% use tmp, in the form below, as many times as needed\begin{document}\expandafter\tmp\expandafter{\myoptions}  \centering  \includegraphics[width=0.5\textwidth]{whatever}  \caption[Short caption citing something]{Long caption.}  \label{fig:whatever}\end{figure}\end{document}

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images