0

My project has many (tex) subfiles that need to be created. I want TeXstudio to auto create all files into my folder.

Example:

\input{datavd/[2D1-VD-2-1]}
\input{datatl/[2D1-BTTT-Y2-1]}
\input{datatl/[2D1-BTTT-B2-1]}
\input{datatl/[2D1-BTTT-K2-1]}
\input{datatl/[2D1-BTTT-G2-1]}

My folder is empty. And I do not want to use Ctrl + Click to create a file. I want to automaticly create them. Thanks.

1
  • One could redefine the \input macro to write an empty file if that file doesn't already exist.
    – Skillmon
    Jul 30, 2018 at 17:59

1 Answer 1

3

With the redefined \input and one TeX run you can create all those files (provided of course, the folder exists):

\documentclass[]{article}

\let\inputoriginal\input
\newwrite\tmpwrite
\makeatletter
\begingroup
\catcode`\%=12
\def\zz
  {\endgroup
    \newcommand*\input@WriteNote[1]
      {\immediate\openout\tmpwrite=##1
        \immediate\write\tmpwrite
          {% automatically created by \string\input}\relax
        \immediate\closeout\tmpwrite
      }
  }
\zz
\renewcommand*\input
  {\@ifnextchar\bgroup{\input@Check}{\input@GrabUndelimited}}
\newcommand\input@GrabUndelimited{}
\long\def\input@GrabUndelimited#1 {\input@Check{#1}}
\newcommand\input@Check[1]
  {\IfFileExists{#1}{\inputoriginal{#1}}{\input@WriteNote{#1}}}
\makeatother

\begin{document}
\input{sub/foo}
\input{sub/bar}
\input sub/baz
\end{document}

Edit:

Allowing undelimited \input argument.

0

This site is temporarily in read-only mode and not accepting new answers.

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