3

my code is the following

\documentclass[ngerman,german,14pt,twoside,openany]{scrbook} %Bei Hochformat [oneside] zusätzlich eintragen und linker Rand 3cm, 2 Spalten und 6cm Bildhöhe
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
%\usepackage[cam,width=216truemm,height=303truemm,center]{crop} %Beschnittzugabe; https://komascript.de/node/786
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{rotating, graphicx}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tikz-timing}
\usepackage{pgffor} % \foreach


\begin{document}


This is just text as part of a test... This is just text as part of a test...This is just text as part of a test... This is just text as part of a test...

\begin{center}
   \foreach \s in {1,...,1000}{%
   \IfFileExists{D:/folder1/folder2/pupil\s.jpg}%
 {\begin{tikzpicture}%
  \def\ig{%
   \includegraphics[width=.48\textwidth,keepaspectratio]{D:/folder1/folder2/pupil\s.jpg}}%
 \node [inner sep=0pt](mypicture) at (0,0) {\phantom{\ig}};%
 \clip[rounded corners=4mm] ($(mypicture.south west)+(1mm,1mm)$) rectangle ($(mypicture.north east)-(1mm,1mm)$);%
 \node[inner sep=0pt](mypicture) at (0,0) {\ig};%
\end{tikzpicture}
\vspace{2mm}
}}
\end{center}

\end{document} 

Here is my question: I am working on a report for a school. In this report approximately 50 pupils will get a text with some photos. Is it possible to modify my code in such a way that the text only appears when the picture "folder 2" contains pictures, otherwise no text should appear. How can this be done? Any help is greatly appreciated! Thanks!

1
  • actually pehaps you just want to move the text inside the loop and have \ifnum\s=1 This is just text as part of a test... This is just text as part of a test...This is just text as part of a test... This is just text as part of a test... \fi so it only appears at most once Apr 19 at 15:45

2 Answers 2

3

You can move the preamble text in to the loop guarded by s=1 and \IfFileExists so that it only appears once if the loop iterates at all and does not appear if there are no files.

\documentclass[ngerman,german,14pt,twoside,openany]{scrbook} %Bei Hochformat [oneside] zusätzlich eintragen und linker Rand 3cm, 2 Spalten und 6cm Bildhöhe
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
%\usepackage[cam,width=216truemm,height=303truemm,center]{crop} %Beschnittzugabe; https://komascript.de/node/786
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{rotating, graphicx}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tikz-timing}
\usepackage{pgffor} % \foreach


\begin{document}


\begin{center}
  \foreach \s in {1,...,10}{%


   \IfFileExists{D:/folder1/folder2/pupil\s.jpg}%
   {%
    \ifnum\s=1   
\parbox{\textwidth}{This is just text as part of a test... This is just text as part of a test...This is just text as part of a test... This is just text as part of a test...}
\fi
\begin{tikzpicture}%
  \def\ig{%
   \includegraphics[width=.48\textwidth,keepaspectratio]{D:/folder1/folder2/pupil\s.jpg}}%
 \node [inner sep=0pt](mypicture) at (0,0) {\phantom{\ig}};%
 \clip[rounded corners=4mm] ($(mypicture.south west)+(1mm,1mm)$) rectangle ($(mypicture.north east)-(1mm,1mm)$);%
 \node[inner sep=0pt](mypicture) at (0,0) {\ig};%
\end{tikzpicture}
\vspace{2mm}
}}
\end{center}

\end{document} 
2
  • A very big thank you for your help, this is what I was looking for!!!!
    – mario1000
    Apr 19 at 15:57
  • 1
    @mario1000 note the other answer will be much faster than checking 1000 files that are not there (I changed this answer to 10 just so it stops quicker) l3sys-query uses Lua to get a file list Apr 19 at 15:59
5

With a current Texlive or miktex you can use the l3sys-query package (part of the core latex tools bundle) then use

\QueryFilesTF{*.jpg}{\node....\includegraphics{#1}}{}{No Files found}
2
  • That looks useful. Is this new in TL2024?
    – user287367
    Apr 19 at 15:33
  • 1
    @rallg yes, and allowed without --shell-escape as it is in the default "safe" list of allowed programs in both texlive and miktex Apr 19 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .