# using commands in optional parameters

If I define a new command like

\newcommand{\command}{htb}


why can't I use this command to set for example the float options of an figure enviroment?

\begin{figure}[\command]
\centering
$f(x) = x^2$
\caption{Some equation}
\end{figure}


this won't compile but this

\begin{figure}[htb]
\centering
$f(x) = x^2$
\caption{Some equation}
\end{figure}


will.

Could someone explain this and maybe how one can set a common setting for all figures

• If you want to change the positioning of every figure environment, you might redefine \fps@figure. The optional argument of float environments is not expanded to check which letters occur in it, you'd have to expand it beforehand, which would be a lot of \expandafters. You could use \newcommand*\myfigure{\begin{figure}[{#1}]} and then use \expandafter\myfigure\expandafter{\command}. – Skillmon likes topanswers.xyz Oct 9 '19 at 16:34

This is primarily based on how LaTeX processes the optional argument to a float. In essence, it captures the optional argument in a different macro (\@fps, specifically), then attempts to expand that macro by looking at it's \meaning. Then it sequentially processes the characters of the meaning. However, the capturing process uses \def, similar to the following setup:

\usepackage[T1]{fontenc}
\def\abc{abc}
\def\ghi{\abc}
\meaning\ghi


which returns In the above output, macro:-> is considered "the prefix", while the exact meaning is \abc. With this analogy, your \command will result in LaTeX processing \, c, o, m, m, a, n, d sequentially and not find any match with the existing set of approved float specifications.

Simple solutions would be to define the default using the kernel functions:

\makeatletter
\def\fps@figure{htb}
\makeatother


Or you could use the float package:

\usepackage{float}
\floatplacement{figure}{htb}


Or, if you're extremely dedicated, you could try a patch on \@xfloat:

\usepackage{etoolbox}

\makeatletter
\patchcmd{\@xfloat}% <cmd>
{\def \@fps}% <search>
{\edef\@fps}% <replace>
{}{}% <success><failure>
\makeatother


The above replaces the traditional \def with an expanded version. It allows you to use your setup

\begin{figure}[\command]
{"ft_lang_label":"__label__en","ft_lang_prob":0.8213754,"math_prob":0.6686642,"size":1705,"snap":"2020-10-2020-16","text_gpt3_token_len":460,"char_repetition_ratio":0.10170488,"word_repetition_ratio":0.0,"special_character_ratio":0.24398828,"punctuation_ratio":0.12080537,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9905012,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-21T13:21:36Z\",\"WARC-Record-ID\":\"<urn:uuid:506faf5d-18d5-4d14-8620-862016abf8bd>\",\"Content-Length\":\"137662\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:937229c6-97e7-4dd5-99a5-a3294ef150a7>\",\"WARC-Concurrent-To\":\"<urn:uuid:2657814f-b566-43e3-a536-f0b2fa631bac>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/511622/using-commands-in-optional-parameters\",\"WARC-Payload-Digest\":\"sha1:DOY7GMWMBWHI6FEVQ62KKTMN6ENMPZ23\",\"WARC-Block-Digest\":\"sha1:DYM46RNKGMVDX7EUWDUJVPBSYCX32QLH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875145529.37_warc_CC-MAIN-20200221111140-20200221141140-00375.warc.gz\"}"}