Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Be careful of reading health books, you might die of a misprint. -- Mark Twain


comp / comp.text.tex / conditional newcommand

SubjectAuthor
* conditional newcommandFrançois Patte
`* Re: conditional newcommandUlrike Fischer
 `- Re: conditional newcommandFrançois Patte

1
Subject: conditional newcommand
From: François Patte
Newsgroups: comp.text.tex
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 11:23 UTC
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: francois.patte@mi.parisdescartes.fr (François Patte)
Newsgroups: comp.text.tex
Subject: conditional newcommand
Date: Sun, 12 Jan 2025 12:23:52 +0100
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <vm08o8$14err$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Jan 2025 12:23:52 +0100 (CET)
Injection-Info: dont-email.me; posting-host="84a821cd3529c780a283709c5d74be18";
logging-data="1194875"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Kk9LbbgLHsFrPe3+CT51A"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aq478NZ6Z6sr5IaXffAkSa4j1HQ=
Content-Language: en-GB, en-US
View all headers

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.

Subject: Re: conditional newcommand
From: Ulrike Fischer
Newsgroups: comp.text.tex
Date: Sun, 12 Jan 2025 11:40 UTC
References: 1
Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: news3@nililand.de (Ulrike Fischer)
Newsgroups: comp.text.tex
Subject: Re: conditional newcommand
Date: Sun, 12 Jan 2025 12:40:56 +0100
Lines: 36
Message-ID: <1hqfsy816m311.dlg@nililand.de>
References: <vm08o8$14err$1@dont-email.me>
Reply-To: news3@nililand.de
Mime-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Im4S3+LDZr1qIkHsoXu2fQ+Ld/j4ggoyBxyByfFHJg7F7pqJT5
Cancel-Lock: sha1:sP9O2VBfFtZlG52J9nImd9kfMVQ= sha256:hDWhAmZgYDEV/CVweXRoqrp/I3ykuVSKeCxvuVi5Lx0=
User-Agent: 40tude_Dialog/2.0.15.41de
View all headers

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/

Subject: Re: conditional newcommand
From: François Patte
Newsgroups: comp.text.tex
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 17:38 UTC
References: 1 2
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: francois.patte@mi.parisdescartes.fr (François Patte)
Newsgroups: comp.text.tex
Subject: Re: conditional newcommand
Date: Sun, 12 Jan 2025 18:38:53 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vm0und$17rt7$2@dont-email.me>
References: <vm08o8$14err$1@dont-email.me> <1hqfsy816m311.dlg@nililand.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 12 Jan 2025 18:38:53 +0100 (CET)
Injection-Info: dont-email.me; posting-host="84a821cd3529c780a283709c5d74be18";
logging-data="1306535"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mwWqh55AVT2+DzZvsCiT9"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9zbFrovN13wwf5sgLwbqQeHIcTE=
Content-Language: en-GB, en-US
In-Reply-To: <1hqfsy816m311.dlg@nililand.de>
View all headers

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.

1

rocksolid light 0.9.8
clearnet tor