GeneralGetting an environment parameter outside the environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jcgarreau
Posts: 1
Joined: Fri Mar 04, 2022 5:50 pm

Getting an environment parameter outside the environment

Post by jcgarreau »

Hello,
Let it be a simple environment with one parameter

Code: Select all

\newenvironment{testenv}[1]
{
#1
}
Used like this

Code: Select all

\begin{testenv}{Any text}
\label{testenv1}
The parameter is '#1'
\end{testvenv}
Is there a way to have access to the to parameter #1 using the environment label? Something like

Code: Select all

\somecommand{testev1}
that would return the value of #1?

Thanks,
JC

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Getting an environment parameter outside the environment

Post by Ijon Tichy »

You can use \gdef to define a macro globally inside the environment. But note: In case of nested usage of the environment, the last \gdef will be the valid one independent of the nest level.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply