I would like to have a single option/macro (true/false or similar) that determines, from which folder to choose plots. There's only 2 folders for each plot.Mainly need this to switch between low resolution/high resolution plots to speedup viewing/compilation of document while writing.With low resolution plots viewing is way faster (I use quite old notebook).I came up with some code, but it gives these errors:1) File ended while scanning use of
__xparse_grab_G_trailing:w.2) ==>Fatal error occurred, no output PDF file produced!
If I use commented \includegraphics
line with hard-coded path, it works of course.
The testPlot.png
file is located under plots/smallPlots
folder.I also usually use \addpic
macro (it generated \includegraphics
code) instead of \includegraphics
, but even this simplified version doesn't work.
Thank you!
Sample code:
\documentclass{article}\usepackage{xparse}\usepackage{graphicx}\usepackage{etoolbox} \newcommand{\IsUseFullSizePlots}{yes} % Path switching parameter. Macro either defined or commented\NewDocumentCommand{\Path}{g}{%plots/\ifdef{\IsUseFullSizePlots}{originalFullSizePlots}{smallPlots} % from etoolbox package}\begin{document} Path = \Path % checking \includegraphics[width=.3\textwidth, clip]{\Path/testPlot}% \includegraphics[width=.3\textwidth, clip]{plots/smallPlots/testPlot}\end{document}
Code for the \addpic
macro (don't understand really how it works, works though :):
\ExplSyntaxOn% the user level command\NewDocumentCommand{\addpic}{m} { \group_begin: % localize the changes to the variables \simonson_pic:n { #1 } \group_end: }% the key-value interface\keys_define:nn { simonson/pic } { placement .tl_set:N = \l_simonson_pic_placement_tl, placement .initial:n = htp, width .tl_set:N = \l_simonson_pic_width_tl, width .initial:n = 1, options .tl_set:N = \l_simonson_pic_options_tl, image .tl_set:N = \l_simonson_pic_image_tl, caption .tl_set:N = \l_simonson_pic_caption_tl, shortcaption .tl_set:N = \l_simonson_pic_shortcaption_tl, label .tl_set:N = \l_simonson_pic_label_tl, }% the main command\cs_new_protected:Nn \simonson_pic:n { % set the keys from the argument \keys_set:nn { simonson/pic } { #1 } % start the figure environment \__simonson_start_figure:V \l_simonson_pic_placement_tl \centering % include the image \__simonson_pic_image:VVV \l_simonson_pic_width_tl % the text width fraction \l_simonson_pic_options_tl % other options \l_simonson_pic_image_tl % the image name % the caption \tl_if_empty:NTF \l_simonson_pic_shortcaption_tl { \caption{\l_simonson_pic_caption_tl} } { \caption[\l_simonson_pic_shortcaption_tl]{\l_simonson_pic_caption_tl} } % the label% In \ addpics \ macro:\ label=\l_simonson_pic_label_tl %for test(my code) \tl_if_empty:NF \l_simonson_pic_label_tl { \label{\l_simonson_pic_label_tl} } % end the figure environment %### %for parser to ignore \end{figure} %###}% syntactic sugar: we want some token lists to be expanded before usage\cs_new_protected:Nn \__simonson_start_figure:n { \begin{figure}[#1] }\cs_generate_variant:Nn \__simonson_start_figure:n { V }\cs_new_protected:Nn \__simonson_pic_image:nnn { \includegraphics[width=#1\textwidth,#2]{#3} }\cs_generate_variant:Nn \__simonson_pic_image:nnn { VVV }\ExplSyntaxOff
===========================================================usage example
\addpic{ width=0.3, image=example-image, caption={This is an example image, and a comma in the caption}, label=one, }