Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Dernière révision Les deux révisions suivantes
2_programmation:macros:cette_commande_est_elle_definie [2021/01/07 19:07]
jejust Ancienne révision (2020/12/09 20:57) restaurée
2_programmation:macros:cette_commande_est_elle_definie [2021/01/07 19:23]
jejust Traduction partielle en français.
Ligne 1: Ligne 1:
-====== ​Is this command defined? ======+====== ​Comment tester si une commande est définie ​? ======
  
 +===== Méthodes traditionnelles =====
  
-Macro sets from the earliest days of TeX programming may be +==== En TeX ====
-observed to test whether commands exist by using +
-''​\ifx\<​command>​\undefined''​ <//​stuff//>​ ... +
-(which of course actually tests that the command //​doesn'​t//​ +
-exist). ​ LaTeX programmers can make use of the internal command +
-''​\@ifundefined{cmd name}{action1}{action2}''​ +
-which executes ''​action1''​ if the command is undefined, and +
-''​action2''​ if it is defined +
-(//cmd name// is the command name only, omitting the ''​\''​ character).+
  
-The ''​\@ifundefined'' ​command is based on the sequence+Voici ce qu'on trouve dans les anciennes macros écrites en <​latex>​\TeX{}</​latex>​ 
 +pour tester l'​existence d'une commande ''<//​commande//>'':​ 
 + 
 +''​\ifx\<//​commande//>​\undefined<//​code à exécuter//>''​ 
 + 
 +(ceci exécute le code si la commande **n'​**existe **pas**, bien sûr). 
 + 
 + 
 +==== En LaTeX ==== 
 + 
 +Quand on programme en <​latex>​\LaTeX{}</​latex>,​ on peut directement utiliser 
 +''​\@ifundefined{<//cmd name//>​}{<//​action1//>​}{<//​action2//>​}''​
 +qui exécute ''<//​action1//>''​ si la commande **n'​**est **pas** définie, 
 +et ''<//​action2//>''​ dans le cas contraire 
 +(''<//​cmd name//>''​ est le nom de la commande tout nu, **sans son antislash** ''​\''​). 
 + 
 +La macro ''​\@ifundefined''​ utilise ce mécanisme:
  
 <code latex> <code latex>
 \expandafter \ifx \csname cmd name\endcsname \relax \expandafter \ifx \csname cmd name\endcsname \relax
 </​code>​ </​code>​
-which relies on the way ''​\csname'' ​worksif the command doesn'​t +qui repose sur le fonctionnement de ''​\csname'':​ 
-existit simply creates it as an alias for ''​\relax''​.+si la commande n'​existe pasil la crée comme alias de ''​\relax''​. 
  
-So: what is wrong with these techniques?+===== Qu'​est-ce qui ne va pas avec ces méthodes ​=====
  
 Using ''​\undefined''​ blithely assumes that the command is indeed not Using ''​\undefined''​ blithely assumes that the command is indeed not
Ligne 34: Ligne 44:
 names serve no purpose whatever. ​ names serve no purpose whatever. ​
  
-David Kastrup offers the (rather tricky)+David Kastrup offers the (rather tricky):
  
 <code latex> <code latex>
Ligne 45: Ligne 55:
 The [[FAQ-etex|ε-TeX system]] system comes to our help here: it The [[FAQ-etex|ε-TeX system]] system comes to our help here: it
 defines two new primitives: defines two new primitives:
-  ​ 
  
   * ''​\ifdefined'',​ which tests whether a thing is defined (the negative of comparing with ''​\undefined'',​ as it were), and   * ''​\ifdefined'',​ which tests whether a thing is defined (the negative of comparing with ''​\undefined'',​ as it were), and
   * ''​\ifcsname cmd name\endcsname'',​ which does the negative of ''​\@ifundefined''​ without the ''​\relax''​-command side-effect.   * ''​\ifcsname cmd name\endcsname'',​ which does the negative of ''​\@ifundefined''​ without the ''​\relax''​-command side-effect.
  
-So, in an <​latex>​$\epsilon$-\TeX{}</​latex>​-based system, the following two conditional clauses do+So, in an ε-<​latex>​\TeX{}</​latex>​-based system, the following two conditional clauses do
 the same thing: the same thing:
  
Ligne 66: Ligne 75:
 \fi \fi
 </​code>​ </​code>​
-However, after using the original LaTeX +However, after using the original LaTeX ''​\@ifundefined{foo}...''​, 
-''​\@ifundefined{foo}''​..., the conditionals will detect the +the conditionals will detect the command as "​existing"​ 
-command as "​existing"​ (since it has been ''​\let''​ to ''​\relax''​);​ +(since it has been ''​\let''​ to ''​\relax''​) ; so it is important 
-so it is important not to mix mechanisms for detecting the state of a +not to mix mechanisms for detecting the state of a command.
-command.+
  
 In the 2018 <​latex>​\LaTeX{}</​latex>​ release, the definition of ''​\@ifundefined''​ was adapted In the 2018 <​latex>​\LaTeX{}</​latex>​ release, the definition of ''​\@ifundefined''​ was adapted
2_programmation/macros/cette_commande_est_elle_definie.txt · Dernière modification: 2021/09/27 23:41 par bdumont
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0