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édentesRévision précédente
Prochaine révision
Révision précédente
composition:texte:renvois:detecter_qu_un_label_est_vide [2018/06/02 15:37] joseph.wright3_composition:texte:renvois:detecter_qu_un_label_est_vide [2021/11/29 22:56] (Version actuelle) – Correction de la mise en forme. yannick.tanguy
Ligne 1: Ligne 1:
---- +====== Comment savoir si une étiquette n'est pas définie? ======
-title: Finding if a label is undefined +
-category: programming +
-tags: latex macros +
-permalink: /FAQ-labundef +
-date: 2014-06-10 +
----+
  
-People seem to want to know (at run time) if a label is undefined (I +Au moment de l'exécution de votre code <latex>\LaTeX</latex>vous pourriez souhaiter savoir si une étiquette n'est pas définie (même si c'est un état transitoire et que <latex>\LaTeX</latex>  gère assez bien cette situation).
-don't actually understand _why_particularly: it's a transient +
-state, and LaTeX deals with it quite well).+
  
-A resolved label is simply a command: +===== Avec les commandes de base =====
-`\r@<label-name>`; determining if the label is set is +
-then simply a matter of detecting if the command exists.  The usual +
-LaTeX internal way of doing this is to use the command +
-`\@ifundefined`: +
-  `\@ifundefined{r@label-name}{undef-cmds}{def-cmds}` +
-In which, &lsaquo;_label-name_&rsaquo; is exactly what you would use in +
-a `\label` command, and the remaining two arguments are command +
-sequences to be used if the label is undefined +
-(&lsaquo;_undef-cmds_&rsaquo;) or if it is defined +
-(&lsaquo;_def-cmds_&rsaquo;).+
  
-Note that any command that incorporates `\@ifundefined` is naturally +Une étiquette définie est simplement une commande : ''\r@''//nom-étiquette//. Notre question initiale revient donc à vérifier si la commande existe. Avec <latex>\LaTeX</latex>cela se fait généralement avec la commande de test ''\@ifundefined{r@''//nom-étiquette//''}{''//cas-non-déf//''}{''//cas-déf//''}'' pour laquelle : 
-fragileso remember to create it with `\DeclareRobustCommand` or to +  * ''nom-étiquette'' est le nom d'étiquette que vous avez utilisé dans la commande ''\label''
-use it with `\protect` in a moving argument.+  * et les deux autres arguments sont les commandes qui seront exécutées si l'étiquette est non définie (''cas-non-déf'') ou si elle est définie (''cas-déf'').
  
-If you're into this game, you may well not care about LaTeX'+Notez que toute commande qui intègre ''\@ifundefined'' est naturellement [[2_programmation:syntaxe:c_est_quoi_la_protection|fragile]]. Pour la protéger, consultez la question « [[2_programmation:syntaxe:c_est_quoi_la_protection|À quoi sert la « protection » ?]] ».
-warning about undefined labels at the end of the document; however, +
-if you are, include the command `\G@refundefinedtrue` in +
-&lsaquo;_`undef-cmds`_&rsaquo;.+
  
-And of courseremember you're dealing in internal commandsand pay +Si vous suivez cette pistevous ne soucierez peut-être pas de l'avertissement de <latex>\LaTeX</latex> concernant les étiquettes non définies à la fin du document. Cependantsi vous y trouvez un intérêt, ajoutez la commande ''\G@refundefinedtrue'' dans l'argument ''cas-non-déf''.
-attention to the [at-signs](FAQ-atsigns).+
  
-All the above can be avoided by using the [`labelcas`](https://ctan.org/pkg/labelcas) package: +Enfinbien sûr, rappelez-vous que vous avez affaire à des commandes internesEn cas de douteconsultez la question : « [[2_programmation:macros:makeatletter_et_makeatother|À quoi servent \makeatletter et \makeatother ?]] ».
-it provides commands that enable you to switch according to the state +
-of a single labelor the states of a list of labels The package'+
-definition is a bit complicatedbut the package itself is pretty +
-powerful.+
  
 +===== Avec l'extension “labelcas” =====
  
 +Tout ce qui précède peut être évité en utilisant l'extension [[ctanpkg>labelcas]] : elle fournit des commandes permettant de d'agir différemment selon l'état d'une étiquette, ou des états d'une liste d'étiquettes. Cette extension, un peu compliquée, s'avère assez puissante.
 +
 +-----
 +
 +//Source:// [[faquk>FAQ-labundef|Finding if a label is undefined]]
 +
 +{{htmlmetatags>metatag-keywords=(LaTeX,commande,macro,programmation,étiquette,définition)
 +metatag-og:title=(Comment savoir si une étiquette n'est pas définie)
 +metatag-og:site_name=(FAQ LaTeX francophone)
 +}}
3_composition/texte/renvois/detecter_qu_un_label_est_vide.1527953836.txt.gz · Dernière modification : 2018/06/02 15:37 de joseph.wright
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0