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
Prochaine révision
Révision précédente
2_programmation:macros:definir_un_caracteres_comme_une_macro [2018/12/02 23:40]
jejust
2_programmation:macros:definir_un_caracteres_comme_une_macro [2021/10/24 23:05]
jejust Mise à jour des liens internes. Mots-clefs OpenGraph.
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 +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): +
 <code latex> <code latex>
 \catcode`\_=\active \catcode`\_=\active
 </​code>​ </​code>​
 +
 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:
- 
 <code latex> <code latex>
 \def//{\//} \def//{\//}
 </​code>​ </​code>​
 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:
- 
 <code latex> <code latex>
 \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
- 
  
 <code latex> <code latex>
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:
- 
  
 <code latex> <code latex>
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:
- 
- 
 <code latex> <code latex>
 \begingroup \begingroup
Ligne 104: Ligne 93:
 </​code>​ </​code>​
  
-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
- 
  
 <code latex> <code latex>
Ligne 128: Ligne 116:
  
  
---- +-----
 //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
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0