0

i'm currently writing an application template. For the appendix i need to be able to include some pdf docs. The name of theese docs are store in an array. So i need to be able to includepdf where the filename comes from that array. But i can't get it working. Here is my mwe (actually my template is much more complex and has a cls file, but i think this does not cause the problem):

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pdfpages}
\usepackage{arrayjob}
\usepackage{forloop}
\newarray\pdfdocs
\pdfdocs(1)={test1}
\pdfdocs(2)={test2}
\newcounter{numofpdfdocs}
\setcounter{numofpdfdocs}{2}
\newcounter{pdfdocsindex}
\begin{document}
    \forloop{pdfdocsindex}{1}{\not{\value{pdfdocsindex} > \value{numofpdfdocs}}}{%
        \includepdf[pages=-]{\pdfdocs(\value{pdfdocsindex})}%
    }%
\end{document}

Whats wrong? In my logfile it states:

! Incomplete iffalse; all text was ignored after line 17.
<inserted text> 
                fi 
<*> main.tex
                                       
! Emergency stop.
<*> main.tex
                                       
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on main.log.
0

I don't know what's going wrong (and currently don't have the time to investigate), but how about using expl3 for this job?

The following defines the macro \placedocsfromlist that loops over a comma separated list of file names and includes those. If you use \placedocsfromlist* the first token of the argument will be expanded (so you could use a list stored inside a macro):

\documentclass[]{article}

\usepackage{pdfpages}

\ExplSyntaxOn
\NewDocumentCommand \placedocsfromlist { s m }
  {
    \IfBooleanT {#1} { \exp_args:No }
    \copper_place_list:n {#2}
  }
\cs_new_protected:Npn \copper_place_list:n #1
  { \clist_map_inline:nn {#1} { \includepdf [pages=-] {##1} } }
\ExplSyntaxOff

\newcommand*\docslist{docA, docB, docC}

\begin{document}
\placedocsfromlist*\docslist

\placedocsfromlist{docA, docB, docC}
\end{document}
0

With expl3 you can easily apply a function on every item in a clist.

\documentclass{scrartcl}
\usepackage{pdfpages}
\usepackage{expl3}

\ExplSyntaxOn

\clist_new:N\pdfdocs
\let\myset\clist_set:Nn

\newcommand\myincludepdf[2][]{%
  \clist_map_inline:Nn\pdfdocs{\includepdf[#1]{##1}}}

\ExplSyntaxOff

\begin{document}

\myset\pdfdocs{test-1, test-2}
\myincludepdf[pages=1-3, scale=.5]{\pdfdocs}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.