Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. documentclass{article}
  2.  
  3. % for example images
  4. usepackage{mwe}
  5.  
  6. % xparse is no necessary but allows a more flexible interface design
  7. usepackage{xparse}
  8. usepackage{graphics}
  9.  
  10. makeatletter
  11. NewDocumentCommandplacefig{m O{} m m}{%
  12. begin{figure}%
  13. centering
  14. includegraphics[#2]{#3}%
  15. caption{#4}%
  16. label{#1}%
  17. end{figure}%
  18. }
  19. NewDocumentCommanddeffig{m O{} m m}{
  20. expandaftergdefcsname fig@r@#1endcsname{%
  21. placefig{#1}[#2]{#3}{#4}%
  22. expandafterglobalexpandafterletcsname fig@r@#1endcsnamerelax
  23. }%
  24. }
  25. letold@refref
  26. renewcommand*ref[1]{%
  27. old@ref{#1}%
  28. ifcsname fig@r@#1endcsnamecsname fig@r@#1endcsnamefi
  29. }
  30. makeatother
  31.  
  32. % define the (possible) figures
  33. deffig{fig:ex-a}[width=.5textwidth]{example-image-a}{This is an example image.}
  34. deffig{fig:ex-b}{example-image-b}{This is another example image.}
  35.  
  36. begin{document}
  37.  
  38. This is the first reference to fig.~ref{fig:ex-a} in the document.
  39.  
  40. Here, we reference fig.~ref{fig:ex-a} again.
  41.  
  42. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement