Does input really just include the file?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
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
):
documentclassarticle
usepackagemypackage
begindocument
beginmyenvirHello
mycommandWorld
endmyenvir
enddocument
Now the mypackage.sty
file (stored in same folder):
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
endcenter
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:
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
inputfcommand
begincenter
endcenter
endinput
And store into a file fcommand.tex
these two lines:
newcommandmycommand[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:
inputfcommandunskip%
and changed the command file content:
newcommandmycommand[1]
test:command arg=##1 environment arg=#1endinput
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.
input
 |Â
show 5 more comments
up vote
4
down vote
favorite
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
):
documentclassarticle
usepackagemypackage
begindocument
beginmyenvirHello
mycommandWorld
endmyenvir
enddocument
Now the mypackage.sty
file (stored in same folder):
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
endcenter
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:
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
inputfcommand
begincenter
endcenter
endinput
And store into a file fcommand.tex
these two lines:
newcommandmycommand[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:
inputfcommandunskip%
and changed the command file content:
newcommandmycommand[1]
test:command arg=##1 environment arg=#1endinput
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.
input
did you see the answer from Martin Scharrer and especially the 2nd comment.
â albert
1 hour ago
By the way, this minimal document replicates your behaviour. For future reference, rather than saying I havefile1.tex
that looks like this, andfile2.tex
that looks like this, and I use them inmain.tex
in this way, try to provide a single, contained copy-and-paste example. I know it may not always be possible.
â Werner
1 hour ago
The issue here is that you're after an environment argument thatmycommandA
knows nothing about. Is your main question that you want to use the argument of the environment (if there was one) in a command that you define inside the environment?
â Werner
1 hour ago
@Werner Yes, I understand you concern (not easy to get through the code when spread in the text). But I wasn't aware of the package filecontent. And given the case (several files involved), I couldn't really do it another way.
â kebs
1 hour ago
@albert Sorry, I have 4 linked questions, with multiple answers ;-) ! You mean the second one here ? About not using include? Not sure it is related here...
â kebs
1 hour ago
 |Â
show 5 more comments
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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
):
documentclassarticle
usepackagemypackage
begindocument
beginmyenvirHello
mycommandWorld
endmyenvir
enddocument
Now the mypackage.sty
file (stored in same folder):
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
endcenter
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:
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
inputfcommand
begincenter
endcenter
endinput
And store into a file fcommand.tex
these two lines:
newcommandmycommand[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:
inputfcommandunskip%
and changed the command file content:
newcommandmycommand[1]
test:command arg=##1 environment arg=#1endinput
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.
input
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
):
documentclassarticle
usepackagemypackage
begindocument
beginmyenvirHello
mycommandWorld
endmyenvir
enddocument
Now the mypackage.sty
file (stored in same folder):
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
endcenter
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:
NeedsTeXFormatLaTeX2e
ProvidesPackagemypackage[version 0.1]
newenvironmentmyenvir[1]
%
inputfcommand
begincenter
endcenter
endinput
And store into a file fcommand.tex
these two lines:
newcommandmycommand[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:
inputfcommandunskip%
and changed the command file content:
newcommandmycommand[1]
test:command arg=##1 environment arg=#1endinput
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.
input
input
asked 2 hours ago
kebs
450512
450512
did you see the answer from Martin Scharrer and especially the 2nd comment.
â albert
1 hour ago
By the way, this minimal document replicates your behaviour. For future reference, rather than saying I havefile1.tex
that looks like this, andfile2.tex
that looks like this, and I use them inmain.tex
in this way, try to provide a single, contained copy-and-paste example. I know it may not always be possible.
â Werner
1 hour ago
The issue here is that you're after an environment argument thatmycommandA
knows nothing about. Is your main question that you want to use the argument of the environment (if there was one) in a command that you define inside the environment?
â Werner
1 hour ago
@Werner Yes, I understand you concern (not easy to get through the code when spread in the text). But I wasn't aware of the package filecontent. And given the case (several files involved), I couldn't really do it another way.
â kebs
1 hour ago
@albert Sorry, I have 4 linked questions, with multiple answers ;-) ! You mean the second one here ? About not using include? Not sure it is related here...
â kebs
1 hour ago
 |Â
show 5 more comments
did you see the answer from Martin Scharrer and especially the 2nd comment.
â albert
1 hour ago
By the way, this minimal document replicates your behaviour. For future reference, rather than saying I havefile1.tex
that looks like this, andfile2.tex
that looks like this, and I use them inmain.tex
in this way, try to provide a single, contained copy-and-paste example. I know it may not always be possible.
â Werner
1 hour ago
The issue here is that you're after an environment argument thatmycommandA
knows nothing about. Is your main question that you want to use the argument of the environment (if there was one) in a command that you define inside the environment?
â Werner
1 hour ago
@Werner Yes, I understand you concern (not easy to get through the code when spread in the text). But I wasn't aware of the package filecontent. And given the case (several files involved), I couldn't really do it another way.
â kebs
1 hour ago
@albert Sorry, I have 4 linked questions, with multiple answers ;-) ! You mean the second one here ? About not using include? Not sure it is related here...
â kebs
1 hour ago
did you see the answer from Martin Scharrer and especially the 2nd comment.
â albert
1 hour ago
did you see the answer from Martin Scharrer and especially the 2nd comment.
â albert
1 hour ago
By the way, this minimal document replicates your behaviour. For future reference, rather than saying I have
file1.tex
that looks like this, and file2.tex
that looks like this, and I use them in main.tex
in this way, try to provide a single, contained copy-and-paste example. I know it may not always be possible.â Werner
1 hour ago
By the way, this minimal document replicates your behaviour. For future reference, rather than saying I have
file1.tex
that looks like this, and file2.tex
that looks like this, and I use them in main.tex
in this way, try to provide a single, contained copy-and-paste example. I know it may not always be possible.â Werner
1 hour ago
The issue here is that you're after an environment argument that
mycommandA
knows nothing about. Is your main question that you want to use the argument of the environment (if there was one) in a command that you define inside the environment?â Werner
1 hour ago
The issue here is that you're after an environment argument that
mycommandA
knows nothing about. Is your main question that you want to use the argument of the environment (if there was one) in a command that you define inside the environment?â Werner
1 hour ago
@Werner Yes, I understand you concern (not easy to get through the code when spread in the text). But I wasn't aware of the package filecontent. And given the case (several files involved), I couldn't really do it another way.
â kebs
1 hour ago
@Werner Yes, I understand you concern (not easy to get through the code when spread in the text). But I wasn't aware of the package filecontent. And given the case (several files involved), I couldn't really do it another way.
â kebs
1 hour ago
@albert Sorry, I have 4 linked questions, with multiple answers ;-) ! You mean the second one here ? About not using include? Not sure it is related here...
â kebs
1 hour ago
@albert Sorry, I have 4 linked questions, with multiple answers ;-) ! You mean the second one here ? About not using include? Not sure it is related here...
â kebs
1 hour ago
 |Â
show 5 more comments
1 Answer
1
active
oldest
votes
up vote
3
down vote
The problem is that when TeX reads the environment command it detects where all the #1
are, but the input
is not processed. When the environment is executed (that is, the underlying myenvir
command is expanded), all the #1
seen previously are replaced by the argument Hello
. So using
beginmyenvirHello
mycommandWorld
endmyenvir
is the same as (minus the comments)
% beginmyenvirHello
inputfcommand
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
The Hello
was lost because it wasn't used anywhere. Now the input
is expanded:
% beginmyenvirHello
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
Then, after the definition is done, the expansion of mycommand
yields:
% beginmyenvirHello
% newcommandmycommand[1] %%% Already defined
% test:command arg=##1 environment arg=#1
begincenter
% environment contents
test:command arg=#1 environment arg=World
% endmyenvir
endcenter
Ans now you're trying to write #1
in the middle of the text, which raises the error:
! You can't use `macro parameter character #' in horizontal mode.
l.40 test:command arg=#
1 environment arg=World
Thanks for answer! I'll need some time to get it all. You have any idea how I can solve the problem (i.e. make the trick work)?
â kebs
1 hour ago
1
@kebs Sorry, I tried, but I couldn't come up with anything clever. The only solution I can think about is to store the argument of the environment in a macro, and use that macro in the definition ofmycommand
. Like this: pastebin.com/2c8DQNt7
â Phelype Oleinik
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
The problem is that when TeX reads the environment command it detects where all the #1
are, but the input
is not processed. When the environment is executed (that is, the underlying myenvir
command is expanded), all the #1
seen previously are replaced by the argument Hello
. So using
beginmyenvirHello
mycommandWorld
endmyenvir
is the same as (minus the comments)
% beginmyenvirHello
inputfcommand
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
The Hello
was lost because it wasn't used anywhere. Now the input
is expanded:
% beginmyenvirHello
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
Then, after the definition is done, the expansion of mycommand
yields:
% beginmyenvirHello
% newcommandmycommand[1] %%% Already defined
% test:command arg=##1 environment arg=#1
begincenter
% environment contents
test:command arg=#1 environment arg=World
% endmyenvir
endcenter
Ans now you're trying to write #1
in the middle of the text, which raises the error:
! You can't use `macro parameter character #' in horizontal mode.
l.40 test:command arg=#
1 environment arg=World
Thanks for answer! I'll need some time to get it all. You have any idea how I can solve the problem (i.e. make the trick work)?
â kebs
1 hour ago
1
@kebs Sorry, I tried, but I couldn't come up with anything clever. The only solution I can think about is to store the argument of the environment in a macro, and use that macro in the definition ofmycommand
. Like this: pastebin.com/2c8DQNt7
â Phelype Oleinik
1 hour ago
add a comment |Â
up vote
3
down vote
The problem is that when TeX reads the environment command it detects where all the #1
are, but the input
is not processed. When the environment is executed (that is, the underlying myenvir
command is expanded), all the #1
seen previously are replaced by the argument Hello
. So using
beginmyenvirHello
mycommandWorld
endmyenvir
is the same as (minus the comments)
% beginmyenvirHello
inputfcommand
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
The Hello
was lost because it wasn't used anywhere. Now the input
is expanded:
% beginmyenvirHello
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
Then, after the definition is done, the expansion of mycommand
yields:
% beginmyenvirHello
% newcommandmycommand[1] %%% Already defined
% test:command arg=##1 environment arg=#1
begincenter
% environment contents
test:command arg=#1 environment arg=World
% endmyenvir
endcenter
Ans now you're trying to write #1
in the middle of the text, which raises the error:
! You can't use `macro parameter character #' in horizontal mode.
l.40 test:command arg=#
1 environment arg=World
Thanks for answer! I'll need some time to get it all. You have any idea how I can solve the problem (i.e. make the trick work)?
â kebs
1 hour ago
1
@kebs Sorry, I tried, but I couldn't come up with anything clever. The only solution I can think about is to store the argument of the environment in a macro, and use that macro in the definition ofmycommand
. Like this: pastebin.com/2c8DQNt7
â Phelype Oleinik
1 hour ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
The problem is that when TeX reads the environment command it detects where all the #1
are, but the input
is not processed. When the environment is executed (that is, the underlying myenvir
command is expanded), all the #1
seen previously are replaced by the argument Hello
. So using
beginmyenvirHello
mycommandWorld
endmyenvir
is the same as (minus the comments)
% beginmyenvirHello
inputfcommand
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
The Hello
was lost because it wasn't used anywhere. Now the input
is expanded:
% beginmyenvirHello
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
Then, after the definition is done, the expansion of mycommand
yields:
% beginmyenvirHello
% newcommandmycommand[1] %%% Already defined
% test:command arg=##1 environment arg=#1
begincenter
% environment contents
test:command arg=#1 environment arg=World
% endmyenvir
endcenter
Ans now you're trying to write #1
in the middle of the text, which raises the error:
! You can't use `macro parameter character #' in horizontal mode.
l.40 test:command arg=#
1 environment arg=World
The problem is that when TeX reads the environment command it detects where all the #1
are, but the input
is not processed. When the environment is executed (that is, the underlying myenvir
command is expanded), all the #1
seen previously are replaced by the argument Hello
. So using
beginmyenvirHello
mycommandWorld
endmyenvir
is the same as (minus the comments)
% beginmyenvirHello
inputfcommand
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
The Hello
was lost because it wasn't used anywhere. Now the input
is expanded:
% beginmyenvirHello
newcommandmycommand[1]
test:command arg=##1 environment arg=#1
begincenter
% environment contents
mycommandWorld
% endmyenvir
endcenter
Then, after the definition is done, the expansion of mycommand
yields:
% beginmyenvirHello
% newcommandmycommand[1] %%% Already defined
% test:command arg=##1 environment arg=#1
begincenter
% environment contents
test:command arg=#1 environment arg=World
% endmyenvir
endcenter
Ans now you're trying to write #1
in the middle of the text, which raises the error:
! You can't use `macro parameter character #' in horizontal mode.
l.40 test:command arg=#
1 environment arg=World
answered 1 hour ago
Phelype Oleinik
19.7k54276
19.7k54276
Thanks for answer! I'll need some time to get it all. You have any idea how I can solve the problem (i.e. make the trick work)?
â kebs
1 hour ago
1
@kebs Sorry, I tried, but I couldn't come up with anything clever. The only solution I can think about is to store the argument of the environment in a macro, and use that macro in the definition ofmycommand
. Like this: pastebin.com/2c8DQNt7
â Phelype Oleinik
1 hour ago
add a comment |Â
Thanks for answer! I'll need some time to get it all. You have any idea how I can solve the problem (i.e. make the trick work)?
â kebs
1 hour ago
1
@kebs Sorry, I tried, but I couldn't come up with anything clever. The only solution I can think about is to store the argument of the environment in a macro, and use that macro in the definition ofmycommand
. Like this: pastebin.com/2c8DQNt7
â Phelype Oleinik
1 hour ago
Thanks for answer! I'll need some time to get it all. You have any idea how I can solve the problem (i.e. make the trick work)?
â kebs
1 hour ago
Thanks for answer! I'll need some time to get it all. You have any idea how I can solve the problem (i.e. make the trick work)?
â kebs
1 hour ago
1
1
@kebs Sorry, I tried, but I couldn't come up with anything clever. The only solution I can think about is to store the argument of the environment in a macro, and use that macro in the definition of
mycommand
. Like this: pastebin.com/2c8DQNt7â Phelype Oleinik
1 hour ago
@kebs Sorry, I tried, but I couldn't come up with anything clever. The only solution I can think about is to store the argument of the environment in a macro, and use that macro in the definition of
mycommand
. Like this: pastebin.com/2c8DQNt7â Phelype Oleinik
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f458216%2fdoes-input-really-just-include-the-file%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
did you see the answer from Martin Scharrer and especially the 2nd comment.
â albert
1 hour ago
By the way, this minimal document replicates your behaviour. For future reference, rather than saying I have
file1.tex
that looks like this, andfile2.tex
that looks like this, and I use them inmain.tex
in this way, try to provide a single, contained copy-and-paste example. I know it may not always be possible.â Werner
1 hour ago
The issue here is that you're after an environment argument that
mycommandA
knows nothing about. Is your main question that you want to use the argument of the environment (if there was one) in a command that you define inside the environment?â Werner
1 hour ago
@Werner Yes, I understand you concern (not easy to get through the code when spread in the text). But I wasn't aware of the package filecontent. And given the case (several files involved), I couldn't really do it another way.
â kebs
1 hour ago
@albert Sorry, I have 4 linked questions, with multiple answers ;-) ! You mean the second one here ? About not using include? Not sure it is related here...
â kebs
1 hour ago