1

I have an automatically generated .tex file containing some content and a couple, usually just one, \newcommand calls.

Usually I display the content and load the commands with \input but sometimes I'd like to just import the commands it defines without displaying anything.

Is there an easy way to achieve it?

EDIT: Here's a little example of what I'd like to do:

table.tex:

\begin{tabular}{|l|r|}
  \hline%
  foo & bar \\
  bar & foo \\
  \hline%
\end{tabular}
\newcommand\tabledata{This is a foo table about bars}

mwe.tex:

\documentclass[a4paper,11pt]{report}

\begin{document}

\begin{table}[h]
  \centering
  \input{table.tex}
  \caption{About this table: \emph{\tabledata}}
\end{table}

\end{document}

Sometimes I'd like to not display the table but just \tabledata while keeping the normal \input behavior working. Also I'd like to keep the \tabledata local but I could do fine with \renewcommand.

I sometimes call \tabledata inside a secondary \ContinuedFloat\caption, but let's not get too specific about my case.

  • It's usually better to split content and macros. Macros should in most cases be in packages or in the preamble, not somewhere in between – user31729 May 14 '16 at 18:17
  • if the content does not change the main file strecture you can use a save box – touhami May 14 '16 at 18:50
  • @touhami: Isn't the macro definition done in the box then too, captured for all time? – user31729 May 14 '16 at 19:04
  • @ChristianHupfer we want to skip text and have the command defined. it's the first and the easiest idea that come to me. – touhami May 14 '16 at 19:24
  • 1
    for the case of your example you can use comment or verbatim packages – touhami May 15 '16 at 12:39
1

Here is two idea.

  1. If the file to be inputed does not change the whole strecture of document (if no command like \section or \global\textheight...) one can do \setbox0=\hbox{\let\def\gdef\input{file}}
  2. In cases like the Example here \begin{ENV}...\end{ENV} the best is to use comment or verbatim packages

For example

\let\ENV=\comment
\let\endENV=\endcomment
  • I like the idea of selectively enable single parts of the included files with comment markers instead of trying to enable just the macros without displaying anything. Approved ;) – filippo May 15 '16 at 15:51

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.