While writing a few macros to wrap around float environments, I stumbled upon failure of macro-expansion (at least I think so) when it comes to storing float specifiers.
main.tex:
\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage{myfig}
\begin{document}
\section{Dummy section}
%\begin{myfig}[b!]
\begin{myfig}
Yadda yadda yadda
\end{myfig}
\end{document}
myfig.sty:
\ProvidesPackage{myfig}
\makeatletter
\newcommand{\@std@float@align}{p!}
%\newenvironment{myfig}[1][t!]{
\newenvironment{myfig}[1][\@std@float@align]{
\begin{figure}[#1]
}{
\end{figure}
}
\makeatother
When compiling with xetex, this gives me:
./main.tex:10: LaTeX Error: Unknown float option `\'.
I tried getting it to work with the strategy proposed in 3. of this answer, trying to understand tex expansion. Judging from me posting this question, I failed. How do I get to store my float specifier in a macro and use it?
\begingroup\edef\x{\endgroup\noexpand\begin{figure}[#1]}\x. If you have a recent enough (later than TeXLive 2019) XeTeX, then\expanded{\noexpand\begin{figure}[#1]}– Phelype Oleinik Mar 27 '20 at 19:32%from ends of lines so your definitions have unwanted space tokens, but as I note in the answer below you do not need the redefinition at all here. – David Carlisle Mar 27 '20 at 19:44\foois\foo, and not whatever\fooexpands to. Using\edef(or\expanded) like that expands everything (except for\begin, which is prefixed with\noexpand) and then starts the figure with\@std@float@alignexpanded. Though David's suggestion of redefining\fps@figureis the proper way of doing this. – Phelype Oleinik Mar 27 '20 at 19:50