# Open group in environment beginning and close it at its end

I'm trying to call a program from within LaTeX via the \input command. The call itself works just fine however I want to pack everything inside an environment in order to make the call more readable.

The problem is that I need to be able to still give some arguments every time. I know that I could do it with a macro with multiple arguments, but it seemed to be cleaner to use an environment for this.

\begin{regression}{pathToFile}
-param1=x
-param2=y
\end{regression}


My goal is to expand the above code to

\input{|"java -jar pathToProgram -path=pathtoFile-param1=x -param2=y"}


My current approach is this one here:

\newenvironment{regression}[1]{\input{|"java -jar pathToProgram -path='#1'}{"}}


So the idea was that I'd open the \input command at the beginning of the environment and close it at it's ending.

However the problem is that Latex interprets the whole thing as one big argument for the \newenvironment command as if there was no after-definition.
How can I get LaTeX to just copy the curly braces in the argument for the \newenvironment command and only treat them as group-delimiters once the environment has been expanded?

• It would be simpler and more natural to define this as a command and use the syntax \regression{pathtofile}{-param1=a -param2=b} – David Carlisle Nov 24 '17 at 15:57
• your start code for the environment is {\input{|"java -jar pathToProgram -path='#1'}{"}} and the end code is missing in the fragment shown. – David Carlisle Nov 24 '17 at 16:05
• Yeah that's the problem... In fact I wanted the last 4 characters to be the end code but as the opening and closing bracket of the \input command are also considered when grouping the whole command it turned out to get interpreted in exactly the way you described – Raven Nov 25 '17 at 8:34

You might do it with environ:

\usepackage{environ}

\NewEnviron{regression}[1]{%
\input{|"java -jar pathToProgram -path=#1 \BODY"}%
}


but I see no advantage in doing

\begin{regression}{pathtoFile}
-param1=x
-param2=y
\end{regression}


over

\newcommand{\regression}[2]{%
\input{|"java -jar pathToProgram -path=#1 #2"}%
}


with the call

\regression{pathtoFile}{
-param1=x
-param2=y
}

• Yep it worked! Thank you very much. Note though that you forgot the closing " in the \input command (just a note for anyone that wants to C&P this code) – Raven Nov 25 '17 at 9:57