• Re: conditional newcommand

    From Ulrike Fischer@21:1/5 to All on Sun Jan 12 12:40:56 2025
    Am Sun, 12 Jan 2025 12:23:52 +0100 schrieb François Patte:

    Bonjour,

    I would like to define a newcommand with 2 different definitions,
    depending if it is used inside or outside a specific environment.

    Is it possible to define a test which returns 0 if the command is used outside the environment and 1 if it is inside the environment?

    sure. lots of commands change their behaviour depending on where
    they are. E.g. all language commands change inside a otherlanguage
    environment.

    How to do it depends on the details, and also what you mean by
    "inside", but e.g.

    \documentclass{article}
    \usepackage{etoolbox}
    \newbool{myspecialenv}
    \newcommand\testcommand{\ifbool{myspecialenv}{1}{0}} \AddToHook{env/minipage/begin}{\booltrue{myspecialenv}}
    \begin{document}
    \testcommand


    \begin{minipage}{3cm}
    \testcommand
    \end{minipage}
    \end{document}



    --
    Ulrike Fischer
    http://www.troubleshooting-tex.de/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Fran=C3=A7ois_Patte?=@21:1/5 to All on Sun Jan 12 12:23:52 2025
    Bonjour,

    I would like to define a newcommand with 2 different definitions,
    depending if it is used inside or outside a specific environment.

    Is it possible to define a test which returns 0 if the command is used
    outside the environment and 1 if it is inside the environment?

    Thank you.

    F.P.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Fran=C3=A7ois_Patte?=@21:1/5 to All on Sun Jan 12 18:38:53 2025
    Le 12/01/2025 à 12:40, Ulrike Fischer a écrit :
    Am Sun, 12 Jan 2025 12:23:52 +0100 schrieb François Patte:

    Bonjour,

    I would like to define a newcommand with 2 different definitions,
    depending if it is used inside or outside a specific environment.

    Is it possible to define a test which returns 0 if the command is used
    outside the environment and 1 if it is inside the environment?

    sure. lots of commands change their behaviour depending on where
    they are. E.g. all language commands change inside a otherlanguage environment.

    How to do it depends on the details, and also what you mean by
    "inside", but e.g.

    \documentclass{article}
    \usepackage{etoolbox}
    \newbool{myspecialenv}
    \newcommand\testcommand{\ifbool{myspecialenv}{1}{0}} \AddToHook{env/minipage/begin}{\booltrue{myspecialenv}}

    Thank you, I could define my command as I wished:
    \providecommand{\croche}{%
    \ifthenelse{\isodd{\testcommand}}{%
    {\textup{\symbol{"0966}}}%
    }%
    {\textup{\bfseries o}}%
    }%

    In fact I have more than one command to define and I failed to find out
    how to use only one ifthenelse test to do so.... I am not very skillful
    in programmation, just curious if this is possible!

    Thank you anyway.

    F.P.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)