I'm not sure whether this is in principle possible, so let me try to explain; consider this MWE:
\documentclass{article} \usepackage[showframe]{geometry} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{tikzpagenodes} % current page text area \usepackage{caption} \pagecolor{yellow!15} % convert rose: -resize 400x200! /tmp/test.png # ImageMagick \begin{document} \begin{center} % {figure}[h!] \centering % %(for figure) \includegraphics[width=1.0\textwidth]{/tmp/test.png} \captionof{figure}[shortdesc]{ % \caption[shortdesc]{ caption lorem ipsum dolor sit amet, text line 01 caption consectetur adipisicing elit text line 02 caption text line 03 } \label{fig:test1} \end{center} % {figure} % \end % https://tex.stackexchange.com/questions/14512/how-to-define-a-figure-size-so-that-it-consumes-the-rest-of-a-page/14514#14514 % needs texing twice: \begin{tikzpicture}[overlay,remember picture] % Caption \node [anchor=south west,outer sep=0pt,inner sep=0pt,text width=\textwidth] (caption) at (current page text area.south west) {% \captionof{figure}[shortdesc]{ % caption lorem ipsum dolor sit amet, text line 01 caption consectetur adipisicing elit text line 02 caption text line 03 }% \label{fig:test2} % has to stand after the caption, to get its number }; % Image \path let \p0 = (0,0), \p1 = (caption.north) in node [inner sep=0pt,outer sep=0pt,anchor=south] at (\x1,\y1) {% \pgfmathsetmacro\imgheight{\y0-\y1-\abovecaptionskip}% \includegraphics[height=\imgheight pt,width=\textwidth,keepaspectratio]{/tmp/test.png}% }; \end{tikzpicture}% \end{document} The first image snippet is my regular pattern of use of {figure} (or {center}, for non-floating) and \includegraphics. Occasionally though, I have to make images fit on bottom of page, for which I use the tikz pattern, as per How to define a figure size so that it consumes the rest of a page? - and that is the second image snippet.
Now, I always get mega frustrated when I wait for a minute for a doc to comile, realize the pic is not where I want, "maybe \vspace{-1em} will help"?, compile, wait, "Nope... maybe \clearpage"? ... etc until I realize I have to use the tikz pattern - which now requires me to rearrange the code snippet :/.
What I like about my typical pattern, is that its contents are basically just these three commands - and their (only) arguments:
\includegraphics[width=1.0\textwidth]{/tmp/test.png} \captionof{figure}[shortdesc]{ % \caption[shortdesc]{ caption lorem ipsum dolor sit amet, text line 01 caption consectetur adipisicing elit text line 02 caption text line 03 } \label{fig:test1} ... and then, I can basically just exchange {figure} for {center} (and caption for \captionof) without changing these innards much.
So, what I'd ultimately want to do, is define a new environment, say {tikzbottomfigure}, so I can write the same pattern inside:
\begin{tikzbottomfigure} \includegraphics[width=1.0\textwidth]{/tmp/test.png} \captionof{figure}[shortdesc]{ % \caption[shortdesc]{ caption lorem ipsum dolor sit amet, text line 01 caption consectetur adipisicing elit text line 02 caption text line 03 } \label{fig:test1} \end{tikzbottomfigure} ... - and this is the part I'm unsure of - I'd want the new environment code to automatically extract the first command \includegraphics... and its arguments (all up to second command) into #1; the second command \captionof... and its contents into #2; and the \label and its contents into #3 -- so that in the new environment definition code, I could simply write:
\begin{tikzpicture}[overlay,remember picture] % Caption \node [anchor=south west,outer sep=0pt,inner sep=0pt,text width=\textwidth] (caption) at (current page text area.south west) {% #2% #3% has to stand after the caption, to get its number }; % Image \path let \p0 = (0,0), \p1 = (caption.north) in node [inner sep=0pt,outer sep=0pt,anchor=south] at (\x1,\y1) {% \pgfmathsetmacro\imgheight{\y0-\y1-\abovecaptionskip}% #1% }; \end{tikzpicture}% Let's for the moment ignore the potential problems of \includegraphics not having the same arguments in both cases; my primary motive is to avoid defining a new environment with multiple arguments, which would force me to use braces to delimit arguments - and thus ultimately force me to rewrite image code snippets again, which is what I want to avoid in the first place.
The only way I can see this working, is if there is a mechanism that can parse/split and extract "commands and their arguments" from a chunk of text (and possibly assign them to individual #1 type arguments later); notably, some commands may span several lines of text, so this shouldn't be just an (ASCII) text line splitter. So, ultimately, my question is - does such a parsing mechanism exist in Latex, so that I could apply it to my intended usage as described?
\mycomm{caption=<text>,shortcaption=<short>,label=<label>,image=<file>,imageopts=<options>}{figure},{center}) usage pattern; and that kind of a\mycommwould require me to rewrite all images code to conform to that pattern. Basically, I'd keep my usual ({figure},{center}) usage pattern as is during work; and if the time comes where bottom alignment is needed, I just change the environment name - instead of re-writing the entire snippet. My answer below shows a way, but probably not too robust. Cheers!format=figureorformat=filltobottomand others, which wouldn't require changing the environment's name, but just the value. Instead of an inflexible format like the one you want, a much more flexible approach.