Does input really just include the file?

The name of the pictureThe name of the pictureThe name of the pictureClash 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 usemacro 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.










share|improve this question





















  • 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










  • 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














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 usemacro 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.










share|improve this question





















  • 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










  • 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












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 usemacro 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.










share|improve this question













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 usemacro 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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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











  • @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










  • 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











  • @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










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





share|improve this answer




















  • 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 of mycommand. Like this: pastebin.com/2c8DQNt7
    – Phelype Oleinik
    1 hour ago










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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





share|improve this answer




















  • 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 of mycommand. Like this: pastebin.com/2c8DQNt7
    – Phelype Oleinik
    1 hour ago














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





share|improve this answer




















  • 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 of mycommand. Like this: pastebin.com/2c8DQNt7
    – Phelype Oleinik
    1 hour ago












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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










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 of mycommand. 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






  • 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















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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke