Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass{article}
- % for example images
- usepackage{mwe}
- % xparse is no necessary but allows a more flexible interface design
- usepackage{xparse}
- usepackage{graphics}
- makeatletter
- NewDocumentCommandplacefig{m O{} m m}{%
- begin{figure}%
- centering
- includegraphics[#2]{#3}%
- caption{#4}%
- label{#1}%
- end{figure}%
- }
- NewDocumentCommanddeffig{m O{} m m}{
- expandaftergdefcsname fig@r@#1endcsname{%
- placefig{#1}[#2]{#3}{#4}%
- expandafterglobalexpandafterletcsname fig@r@#1endcsnamerelax
- }%
- }
- letold@refref
- renewcommand*ref[1]{%
- old@ref{#1}%
- ifcsname fig@r@#1endcsnamecsname fig@r@#1endcsnamefi
- }
- makeatother
- % define the (possible) figures
- deffig{fig:ex-a}[width=.5textwidth]{example-image-a}{This is an example image.}
- deffig{fig:ex-b}{example-image-b}{This is another example image.}
- begin{document}
- This is the first reference to fig.~ref{fig:ex-a} in the document.
- Here, we reference fig.~ref{fig:ex-a} again.
- end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement