Advertisement
fortin

Sub- and superscripting style (adapted from gb4e) - subperscript.sty

Jun 6th, 2023
1,950
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 1.90 KB | Writing | 0 0
  1. % -*- LaTeX -*-
  2. \ProvidesPackage{subperscript}
  3. %%%%%%%%%%% AUTOMATH
  4.  
  5. % this allows _ to be used in horizontal mode (from J.Frampton):
  6. % Reimplemented to allow this feature to be turned on and off.
  7. % The new version also combines sub- and superscripts properly.
  8. % -Alexis
  9.  
  10. % Sub- and superscripting functionality from gb4e, packaged by Antonio Fortin
  11.  
  12. % \automath     Make _ and ^ work outside math mode
  13. % \noautomath   Restore normal sub/superscript behavior
  14.  
  15. { % Temporarily change catcodes
  16.   \catcode`\_=\active
  17.   \catcode`\^=\active
  18.  
  19.   \global\def\automath{%
  20.     \catcode`\_=\active
  21.     \catcode`\^=\active
  22.     \def_##1{\gb@ifnextchar^{\automath@two_{##1}}{\ensuremath{\sb{##1}}}}%
  23.     \def^##1{\gb@ifnextchar_{\automath@two^{##1}}{\ensuremath{\sp{##1}}}}}
  24. }
  25. \def\automath@two#1#2#3#4{\ensuremath{#1{#2}\relax #3{#4}}}
  26. % Restore default catcodes for ^, _
  27. \def\noautomath{\catcode`\_=8 \catcode`\^=7 }
  28.  
  29. % The original \@ifnextchar discards spaces when looking for the next
  30. % ``character''. This variant accepts any token.
  31. \long\def\gb@ifnextchar#1#2#3{%
  32.   \let\reserved@d=#1%
  33.   \def\reserved@a{#2}%
  34.   \def\reserved@b{#3}%
  35.   \futurelet\@let@token\@gbifnch}
  36. \def\@gbifnch{%
  37.     \ifx\@let@token\reserved@d
  38.       \let\reserved@c\reserved@a
  39.     \else
  40.       \let\reserved@c\reserved@b
  41.     \fi
  42.   \reserved@c}
  43.  
  44. \noautomath % On by default, for backward compatibility
  45.  
  46. %%%%%%%%%
  47.  
  48.  
  49. \def\lb#1{\@ifnextchar [{\@glarph{#1}}{\@bl{#1}}}
  50. \def\@glarph#1[#2]{\ifmmode{[}\sb{{\mathrm{#1}}\sb{#2}}\else%
  51.                            ${[}\sb{{\mathrm{#1}}\sb{#2}}$\fi}
  52. \def\@bl#1{\ifmmode{[}\sb{\mathrm{#1}}\;\else${[}\sb{\mathrm{#1}}\;$\fi}
  53. \def\rb#1{\@ifnextchar [{\@grarph{#1}}{\@br{#1}}}
  54. \def\@grarph#1[#2]{\ifmmode{]}\sb{{\mathrm{#1}}\sb{#2}}\else%
  55.                         ${]}\sb{{\mathrm{#1}}\sb{#2}}$\fi}
  56. \def\@br#1{\ifmmode{]}\sb{\mathrm{#1}}\;\else${]}\sb{\mathrm{#1}}\;$\fi}
  57.  
  58. %%% END_NEWSTUFF.
Tags: LaTeX
Advertisement
Comments
  • fortin
    339 days
    # Markdown 0.28 KB | 0 0

    Allows _ to be used in horizontal mode (from J. Frampton):
    Reimplemented to allow this feature to be turned on and off.
    The new version also combines sub- and superscripts properly.

    • Alexis Dimitriadis

    Sub- and superscripting functionality from gb4e, packaged by Antonio Fortin

Add Comment
Please, Sign In to add comment
Advertisement