Différences

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

 2_programmation:macros:definir_un_caracteres_comme_une_macro [2018/12/04 00:25]jejust 2_programmation:macros:definir_un_caracteres_comme_une_macro [2021/10/24 23:05]jejust Mise à jour des liens internes. Mots-clefs OpenGraph. Les deux révisions précédentes Révision précédente 2021/10/24 23:05 jejust Mise à jour des liens internes. Mots-clefs OpenGraph.2018/12/04 00:25 jejust 2018/12/02 23:40 jejust 2018/06/03 16:21 joseph.wright 2018/06/03 16:16 samcarter 2018/06/03 15:33 d.p.carlisle 2018/06/03 15:31 samcarter 2018/06/03 15:16 samcarter 2018/06/03 15:15 joseph.wright 2018/06/03 15:15 d.p.carlisle 2018/06/03 15:11 samcarter 2018/06/03 15:03 joseph.wright 2018/06/03 15:02 samcarter 2018/06/03 14:57 joseph.wright 2018/06/03 11:58 d.p.carlisle 2018/06/02 17:34 joseph.wright 2018/06/02 16:44 d.p.carlisle 2018/05/31 15:28 d.p.carlisle 2018/05/28 21:29 d.p.carlisle 2018/05/25 23:17 joseph.wright 2018/05/25 21:31 joseph.wright 2018/05/25 10:57 joseph.wright 2018/05/25 10:55 joseph.wright 2018/05/25 00:02 joseph.wright 2018/05/25 00:02 joseph.wright 2018/05/24 19:06 joseph.wright 2018/05/24 18:57 joseph.wright 2021/10/24 23:05 jejust Mise à jour des liens internes. Mots-clefs OpenGraph.2018/12/04 00:25 jejust 2018/12/02 23:40 jejust 2018/06/03 16:21 joseph.wright 2018/06/03 16:16 samcarter 2018/06/03 15:33 d.p.carlisle 2018/06/03 15:31 samcarter 2018/06/03 15:16 samcarter 2018/06/03 15:15 joseph.wright 2018/06/03 15:15 d.p.carlisle 2018/06/03 15:11 samcarter 2018/06/03 15:03 joseph.wright 2018/06/03 15:02 samcarter 2018/06/03 14:57 joseph.wright 2018/06/03 11:58 d.p.carlisle 2018/06/02 17:34 joseph.wright 2018/06/02 16:44 d.p.carlisle 2018/05/31 15:28 d.p.carlisle 2018/05/28 21:29 d.p.carlisle 2018/05/25 23:17 joseph.wright 2018/05/25 21:31 joseph.wright 2018/05/25 10:57 joseph.wright 2018/05/25 10:55 joseph.wright 2018/05/25 00:02 joseph.wright 2018/05/25 00:02 joseph.wright 2018/05/24 19:06 joseph.wright 2018/05/24 18:57 joseph.wright 2018/05/24 10:38 joseph.wright 2018/05/24 10:38 joseph.wright 2018/05/24 10:29 joseph.wright 2018/05/23 23:25 joseph.wright 2018/05/23 23:19 joseph.wright 2018/05/23 22:25 joseph.wright 2018/05/23 18:46 joseph.wright 2018/05/23 15:55 d.p.carlisle 2018/05/22 21:39 joseph.wright 2018/05/22 13:40 joseph.wright 2018/05/22 13:34 joseph.wright créée Ligne 3: Ligne 3: Single characters can act as macros (defined commands), and both Single characters can act as macros (defined commands), and both - Plain TeX and LaTeX define the character + Plain TeX and LaTeX define the character ''​~''​ as a "​non-breakable space"​. - ''​~''​ as a "​non-breakable space"​. ​ A + A character is made definable, or "​active",​ by setting its - character is made definable, or "​active",​ by setting its + //[[2_programmation:​syntaxe:​catcodes:​start|category code]]// (catcode) to be ''​\active''​ (13): - //category code// (catcode) to be ''​\active''​ (13): + \catcode\_=\active \catcode\_=\active ​ + Any character could, in principle, be activated this way and defined Any character could, in principle, be activated this way and defined as a macro: as a macro: - \def//{\//} \def//{\//} ​ which could be characterised as an over-simple answer to which could be characterised as an over-simple answer to - [[FAQ-underscore|using underscores]]. ​ However, you must be + [[3_composition:​texte:​symboles:​caracteres:​tiret|using underscores]]. - wary: whereas people expect an active tilde, other active characters + However, you must be wary: whereas people expect an active tilde, other - may be unexpected and interact badly with other macros. ​ Furthermore,​ + active characters may be unexpected and interact badly with other macros. - by defining an active character, you preclude the character'​s use for + Furthermore,​ by defining an active character, you preclude the character'​s use - other purposes, and there are few characters "​free"​ to be subverted + for other purposes, and there are few characters "​free"​ to be subverted in this way. in this way. To define the character ''​z''​ as a command, one would say something To define the character ''​z''​ as a command, one would say something like: like: - \catcode\z=\active \catcode\z=\active Ligne 34: Ligne 31: and each subsequent ''​z''​ in the text would become a and each subsequent ''​z''​ in the text would become a yawn. This would be an astoundingly bad idea for most documents, but yawn. This would be an astoundingly bad idea for most documents, but - might have special applications. ​ (Note that, in + might have special applications. ​ (Note that, in  ''​\def ​ z'', ​ - ''​\def ​ z'', ​ + ''​z''​ is no longer interpreted as a letter; the space ''​z''​ is no longer interpreted as a letter; the space is therefore not necessary --- ''​\defz''​ would do; we choose to is therefore not necessary --- ''​\defz''​ would do; we choose to retain the space, for what little clarity we can manage.) retain the space, for what little clarity we can manage.) Some LaTeX packages facilitate such definitions. For example, the Some LaTeX packages facilitate such definitions. For example, the - [[ctanpkg>​shortvrb|shortvrb]] package with its ''​\MakeShortVerb''​ command. + [[ctanpkg>​shortvrb]] package with its ''​\MakeShortVerb''​ command. TeX uses category codes to interpret characters as they are read TeX uses category codes to interpret characters as they are read from the input. from the input. //Changing a catcode value will not affect characters that have already been read//. //Changing a catcode value will not affect characters that have already been read//. - Therefore, it is best if characters have fixed category codes for the + Therefore, it is best if characters have fixed category codes for the duration of a document. - duration of a document. ​ If catcodes are changed for particular + If catcodes are changed for particular purposes (the ''​\verb''​ command does this), then - purposes (the ''​\verb''​ command does this), then the altered + the altered characters will not be interpreted properly when they appear in the - characters will not be interpreted properly when they  appear in the + argument to another command (as, for example, in argument to another command (as, for example, in - "[[FAQ-verbwithin|''​\verb'' ​in command arguments]]"​). + "[[3_composition:​texte:​paragraphes:​pourquoi_verbatim_ne_fonctionne_pas_toujours|“\verb” in command arguments]]"​). - An exemplary case is the [[ctanpkg>​doc|doc]] package, which processes .dtx + An exemplary case is the [[ctanpkg>​doc]] package, which processes ​''​.dtx''​ - files using the [[ctanpkg>​shortvrb|shortvrb]] package to define + files using the [[ctanpkg>​shortvrb]] package to define ''​|''​...''​|''​ as a shorthand - ''​|''​...''​|''​ as a shorthand ​for + for ''​\verb|''​...''​|''​. But ''​|''​ is also used in the preambles of tabular environments,​ - ''​\verb|''​...''​|''​. But ''​|''​ is + so that tables in ''​.dtx''​ files can only have vertical line separation between - also used in the preambles of tabular environments,​ so that tables in + - ''​dtx''​ files can only have vertical line separation between + columns by employing special measures of some sort. columns by employing special measures of some sort. Another consequence is that catcode assignments made Another consequence is that catcode assignments made in macros often don't work as expected ​ in macros often don't work as expected ​ - (see "[[FAQ-actinarg|Active characters in command arguments]]"​). + (see "[[2_programmation:​macros:​caracteres_actifs_dans_les_arguments_d_une_macro|Active characters in command arguments]]"​). For example, the definition For example, the definition - Ligne 76: Ligne 68: underscore character already in the macro definition. ​ Instead, one may underscore character already in the macro definition. ​ Instead, one may use: use: - Ligne 94: Ligne 85: can fool ''​\lowercase''​ into patching up a definition without ever can fool ''​\lowercase''​ into patching up a definition without ever explicitly changing a catcode: explicitly changing a catcode: - - \begingroup \begingroup Ligne 104: Ligne 93: ​ - The two definitions have the same overall effect (the character is + The two definitions have the same overall effect (the character is defined - defined as a command, but the character does not remain active), + as a command, but the character does not remain active), except that - except that the first defines a ''​\global''​ command. + the first defines a ''​\global''​ command. For active characters to be used only in maths mode, it is much better For active characters to be used only in maths mode, it is much better to leave the character having its ordinary catcode, but assign it a to leave the character having its ordinary catcode, but assign it a special active //maths code//, as with special active //maths code//, as with - Ligne 129: Ligne 117: ----- ----- - //Source:// [[faquk>​FAQ-activechars|Defining characters as macros]] //Source:// [[faquk>​FAQ-activechars|Defining characters as macros]] - {{htmlmetatags>​metatag-keywords=(LaTeX,​programming) + {{htmlmetatags>​metatag-keywords=(LaTeX,​programmation en LaTeX,​définir des macros,​définir des commandes,​catcodes,​caractères actifs,​commande à un seul caractère,​macro à un seul caractère) metatag-og:​title=(Defining characters as macros) metatag-og:​title=(Defining characters as macros) metatag-og:​site_name=(FAQ LaTeX francophone) metatag-og:​site_name=(FAQ LaTeX francophone) }} }}
2_programmation/macros/definir_un_caracteres_comme_une_macro.txt · Dernière modification: 2021/10/24 23:05 par jejust