Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison docs/lexer-algpseudocode.rst @ 288:298841bc4dee
Allow "normal" Pygments token names in "\ttX" ("Error", "Text.Whitespace", ...)
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 22 May 2026 12:32:38 +0200 |
| parents | 051c8877ee22 |
| children | 6fc7f9c1d89d |
comparison
equal
deleted
inserted
replaced
| 287:f506d752e801 | 288:298841bc4dee |
|---|---|
| 482 | 482 |
| 483 The current and recommended use is the ``\ttX{ARG1}{ARG2}`` command. | 483 The current and recommended use is the ``\ttX{ARG1}{ARG2}`` command. |
| 484 | 484 |
| 485 This command has two required parameters: | 485 This command has two required parameters: |
| 486 | 486 |
| 487 #. The content of the first argument `ARG1` must be a `value` in the | 487 #. The content of the first argument `ARG1` can be one of |
| 488 :py:data:`pygments.token.STANDARD_TYPES` dict. | 488 |
| 489 Its corresponding token type (the associated `key` in this dictionary) | 489 - A `value` in the :py:data:`pygments.token.STANDARD_TYPES` dict. |
| 490 will be used as token type for the token. | 490 |
| 491 Its corresponding token type (the associated `key` in this | |
| 492 dictionary) will be used as token type for the token. | |
| 493 | |
| 494 - A string representation of an existing token type without the | |
| 495 ``Token.`` prefix | |
| 496 (e.g. ``String``, ``Generic``, ``Generic.EmphStrong``, ``Text``, | |
| 497 ``Text.Multiline``). | |
| 491 | 498 |
| 492 If a corresponding token type is not found the lexer's behaviour depends | 499 If a corresponding token type is not found the lexer's behaviour depends |
| 493 on the lexer option ``strict_tokentype`` (see `Lexer Options`_): | 500 on the lexer option ``strict_tokentype`` (see `Lexer Options`_): |
| 494 | 501 |
| 495 If ``True`` (the default) the command yields a | 502 If ``True`` (the default) the command yields a |
| 496 :py:class:`pygments.token.Token.Generic.Error` token type for the | 503 :py:class:`pygments.token.Token.Generic.Error` token type for the |
| 497 given command's content. | 504 given command's content. |
| 498 | 505 |
| 499 If ``False`` then the `Pygments`_ function | 506 If ``False`` then the `Pygments`_ function |
| 500 :py:func:`pygments.token.string_to_tokentype` will be called. | 507 :py:func:`pygments.token.string_to_tokentype` will be called. |
| 501 This function yields either an existing token type or synthesizes | 508 This function returns either an existing token type or synthesizes |
| 502 a new one on the fly. | 509 a new one on the fly. |
| 503 The associated highlighting in the output may not be well defined. | 510 The associated highlighting with freshly created token types in the |
| 511 output may not be well defined. | |
| 504 | 512 |
| 505 For this argument escaping is neither needed nor supported. | 513 For this argument escaping is neither needed nor supported. |
| 506 | 514 |
| 507 #. The content of the second argument will given the token type of | 515 #. The content of the second argument will given the token type of |
| 508 the first parameter. | 516 the first parameter. |
| 509 | 517 |
| 510 Standard `Escaping Rules`_ apply to this argument! | 518 Standard `Escaping Rules`_ apply to this argument! |
| 511 | 519 |
| 512 Examples: | 520 .. rubric:: Examples: |
| 513 | 521 |
| 514 .. code-block:: algpseudocode | 522 .. code-block:: algpseudocode |
| 515 | 523 |
| 516 \text{• \\ttX{kc\}{C\}} \ttX{kc}{C} \rem C as Keyword.Constant | 524 \text{• \\ttX{\}{token\}} \ttX{}{token} \rem just a base "Token" |
| 517 \text{• \\ttX{ow\}{∈\}} \ttX{ow}{∈} \rem ∈ as Operator.Word | 525 |
| 526 \text{• \\ttX{kc\}{C\}} \ttX{kc}{C} \rem C as Keyword.Constant | |
| 527 \text{• \\ttX{Keyword.Constant\}{C\}} \ttX{kc}{C} \rem C as Keyword.Constant | |
| 528 \text{• \\ttX{ow\}{∈\}} \ttX{ow}{∈} \rem ∈ as Operator.Word | |
| 529 \text{• \\ttX{Operator.Word\}{∈\}} \ttX{ow}{∈} \rem ∈ as Operator.Word | |
| 518 \text{• \\ttX{kc\}{A Constant Keyword\}} \ttX{kc}{A Constant Keyword} \rem An explicit Keyword.Constant | 530 \text{• \\ttX{kc\}{A Constant Keyword\}} \ttX{kc}{A Constant Keyword} \rem An explicit Keyword.Constant |
| 519 \text{• \\ttX{nv\}{A Variable Name\}} \ttX{nv}{A Variable Name} \rem An explicit Name.Variable | 531 \text{• \\ttX{nv\}{A Variable Name\}} \ttX{nv}{A Variable Name} \rem An explicit Name.Variable |
| 520 \text{• \\ttX{ni\}{An Entity*Name\}} \ttX{ni}{An Entity*Name} \rem An explicit Name.Entity | 532 \text{• \\ttX{ni\}{An Entity*Name\}} \ttX{ni}{An Entity*Name} \rem An explicit Name.Entity |
| 521 \text{• \\ttX{k\}{∈ ∌\}} \ttX{k}{∈ ∌} \rem ∈ and ∌ as (ordinary) Keywords | 533 \text{• \\ttX{k\}{∈ ∌\}} \ttX{k}{∈ ∌} \rem ∈ and ∌ as (ordinary) Keywords |
| 522 \text{• \\ttX{o\}{∈ ∌\}} \ttX{o}{∈ ∌} \rem ∈ and ∌ as (ordinary) Operators | 534 \text{• \\ttX{o\}{∈ ∌\}} \ttX{o}{∈ ∌} \rem ∈ and ∌ as (ordinary) Operators |
| 523 /* | 535 /* |
| 524 * The line below has ∈_∌ as (peculiar) function name. | 536 * The line below has ∈_∌ as (peculiar) function name. |
| 525 * Their params are automatic (i.e. a normal expression). | 537 * Their params are automatic (i.e. a normal expression). |
| 526 */ | 538 */ |
| 527 \text{• \\ttX{nf\}{∈_∌\}(p1, p2)} \ttX{nf}{∈_∌}(p1, p2) | 539 \text{• \\ttX{nf\}{∈_∌\}(p1, p2)} \ttX{nf}{∈_∌}(p1, p2) |
| 540 \text{• \\ttX{Name.Function\}{∈_∌\}(p1, p2)} \ttX{Name.Function}{∈_∌}(p1, p2) | |
| 528 /* | 541 /* |
| 529 * The line below has ∈_∌ as (peculiar) decorator name (as used in Python). | 542 * The line below has ∈_∌ as (peculiar) decorator name (as used in Python). |
| 530 * Their params are automatic (i.e. a normal expression). | 543 * Their params are automatic (i.e. a normal expression). |
| 531 */ | 544 */ |
| 532 \text{• \\ttX{nd\}{∈_∌\}(p1, p2)} \ttX{nd}{∈_∌}(p1, p2) | 545 \text{• \\ttX{nd\}{∈_∌\}(p1, p2)} \ttX{nd}{∈_∌}(p1, p2) |
| 546 \text{• \\ttX{Name.Decorator\}{∈_∌\}(p1, p2)} \ttX{Name.Decorator}{∈_∌}(p1, p2) | |
| 533 /* | 547 /* |
| 534 * Normal emphasis ("strong") | 548 * Normal emphasis ("strong") |
| 535 */ | 549 */ |
| 536 \text{• \\ttX{gs\}{this is strong\}} \ttX{gs}{this is strong} | 550 \text{• \\ttX{gs\}{this is strong\}} \ttX{gs}{this is strong} |
| 551 \text{• \\ttX{Generic.Strong\}{this is strong\}} \ttX{Generic.Strong}{this is strong} | |
| 537 /* | 552 /* |
| 538 * A strong emphasis. | 553 * A strong emphasis. |
| 539 * Note that the backslash is a valid delimiter! | 554 */ |
| 540 */ | 555 \text{• \\ttX{ges\}{A Strong Emphasis!\}} \ttX{ges}{A Strong Emphasis!} |
| 541 \text{• \\ttX{ges\}{A Strong Emphasis!\}} \ttX{ges}{A Strong Emphasis!} | 556 \text{• \\ttX{Generic.EmphStrong\}{A Strong Emphasis!\}} \ttX{Generic.EmphStrong}{A Strong Emphasis!} |
| 542 /* | 557 /* |
| 543 * Escaping is allowed and needed for the closing brace! | 558 * Escaping is allowed and needed for the closing brace! |
| 544 * The example token type is a "String". | 559 * The example token type is a "String". |
| 545 */ | 560 */ |
| 546 \text{• \\ttX{s\}{Escaping brace \\\} and backslash \\\\!\}} \ttX{s}{Escaping brace \} and backslash \\!} | 561 \text{• \\ttX{s\}{Escaping brace \\\} and backslash \\\\!\}} \ttX{s}{Escaping brace \} and backslash \\!} |
| 548 * This is a non-existing token type: | 563 * This is a non-existing token type: |
| 549 * by default you get some generic error markup with a Generic.Error | 564 * by default you get some generic error markup with a Generic.Error |
| 550 * token and no expansion. | 565 * token and no expansion. |
| 551 * See also `Lexer Options` and `strict_tokentype`. | 566 * See also `Lexer Options` and `strict_tokentype`. |
| 552 */ | 567 */ |
| 553 \text{• \\ttX{NON-EXISTING\}{∈_∌\}(p1, p2)} \ttX{NON_EXISTING}{∈_∌}(p1, p2) | 568 \text{• \\ttX{NON-EXISTING\}{∈_∌\}(p1, p2)} \ttX{NON-EXISTING}{∈_∌}(p1, p2) |
| 554 | 569 |
| 555 An example with a lexer and ``strict_tokentype=False`` | 570 An example with a lexer and ``strict_tokentype=False`` |
| 556 (highlighting obviously is like standard text with the templates used): | 571 (highlighting obviously is like standard text with the templates used): |
| 557 | 572 |
| 558 .. code-block:: nonstrict-algpseudocode | 573 .. code-block:: nonstrict-algpseudocode |
| 559 | 574 |
| 560 \text{• \\ttX{Generic.Not.Yet.Existing\}{∈_∌\}(p1, p2)} \ttX{Generic.Not.Yet.Existing}{∈_∌}(p1, p2) | 575 \text{• \\ttX{Generic.Not.Yet.Existing\}{∈_∌\}(p1, p2)} \ttX{Generic.Not.Yet.Existing}{∈_∌}(p1, p2) |
| 561 | |
| 562 | 576 |
| 563 | 577 |
| 564 Old Syntax (Deprecated) | 578 Old Syntax (Deprecated) |
| 565 ----------------------- | 579 ----------------------- |
| 566 | 580 |
