TransWikia.com

Macro - Introduce a constant to differ the index of the right-hand side image, compared to the left-hand side image

TeX - LaTeX Asked by O0123 on January 28, 2021

Consider the answer of Ulrich Diez of this post: pgfmathsetlengthmacro uncompatible with a loop?:

documentclass[]{article}

usepackage[most]{tcolorbox}

% Define the command NiceForEachElement to ensure error-message in case it is already defined.
% This way you can ensure to a certain degree that using `niceelement` as Foreach-variable
% does not override something that alerady exists.
newcommandNiceForEachElement{}%

newcommandUseImageLeft[2]{%
% #1 preceding phrase "image-"
% #2 number of image
IfFileExists{#1#2.jpg}%
  {includegraphics[scale=0.2]{#1#2.jpg}}%
    {includegraphics[scale=0.2]{example-image.jpg}}%
}

newcommand*ImageLeft[1]{UseImageLeft{Image-}{#1}}

% Problem ===================================
%pgfmathsetlengthmacroLeftWidth{width("ImageLeft")}
% =======================================

begin{document}

% outside the loop the width of Image-7.jpg or example-image.jpg:

pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{7}")}%
%Activate the following line in case you wish to see on screen/console what the definition of LeftWidth looks like now:
%showLeftWidth

% inside the loop:

foreach NiceForEachElement in {1,...,3}{%
  pgfmathsetlengthmacroLeftWidth{width("noexpandnoexpandnoexpandImageLeft{NiceForEachElement}")}%
  %Activate the following line in case you wish to see on screen/console  what the definition of LeftWidth looks like now:
  %showLeftWidth
  % On any page (begin)
  begin{tcolorbox}[]%
  begin{tcbitemize}[]%
  tcbitem[] ImageLeft{NiceForEachElement}%
  end{tcbitemize}%
  end{tcolorbox}%
  % On any page (end)
  newpage
}

end{document}

It compiles great.

One can see that this outputs an image, using tcbitem[] ImageLeft{NiceForEachElement}%.

The name of the image then is Image-1.jpg, on the subsequent page Image-2.jpg and on the subsequent page Image-3.jpg because of foreach NiceForEachElement in {1,...,3}{%.

This is great! My question now is: how do I also output an ImageRight on each page, using

tcbitem[] ImageRight{...}%

which does not have the exact same index {1,...,3}{% but rather this exact same index plus a fixed constant.

If the constant would be 5, then the index of the right-hand side image should be Image-6.jpg, on the subsequent page Image-7.jpg and on the subsequent page Image-8.jpg

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP