Quantcast
Channel: Does \input really just include the file? - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Does \input really just include the file?

$
0
0

I have an issue with the \input command.

As it is stated here, "it's equivalent to typing all the commands from filename.tex right into the current file where the \input line is."

I have the feeling that this is not exactly the case, at least in some situations, and I would like some clarifications.

Consider this MVCE (say, in a file main.tex):

\documentclass{article}
\usepackage{mypackage}
\begin{document}
\begin{myenvir}{Hello}
\mycommand{World}
\end{myenvir}
\end{document}

Now the mypackage.sty file (stored in same folder):

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage}[version 0.1]

\newenvironment{myenvir}[1]
{%
    \newcommand{\mycommand}[1]
    { test:command arg=##1 environment arg=#1}
    \begin{center}
}
{\end{center}} 
\endinput

When compiling main.tex, this works fine, and produces.

test:command arg=World environment arg=Hello

But now, lets say for some reason (*), I want to store the command definition in a separate file. So I just change the sty file to:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage}[version 0.1]

\newenvironment{myenvir}[1]
{%
    \input{fcommand}
    \begin{center}
}
{\end{center}} 
\endinput

And store into a file fcommand.tex these two lines:

\newcommand{\mycommand}[1]
{ test:command arg=##1 environment arg=#1}

Shouldn't that give strictly the same result?

But when compiling main.tex I get this error:

You can't use `macro parameter character # in horizontal mode

and the output (pdf) file holds:

test:command arg=1 environment arg=World

Question: what is going on ? A far as I understand, there seems to be a problem with argument substitution when code is in a separate file. Thus my assumption that \input is not truly equivalent to having the code in same file.

I have also checked this related question, where the answer states to add \unskip. So I tried this:

\input{fcommand}\unskip%

and changed the command file content:

\newcommand{\mycommand}[1]
{ test:command arg=##1 environment arg=#1}\endinput

But still got the same error.

Other related question: https://tex.stackexchange.com/a/319512/11083

(*) On the reason to try this, this question is actually a follow up on another question I am currently dealing with.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>