diff options
author | Karl Berry <karl@freefriends.org> | 2017-06-05 23:19:32 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-06-05 23:19:32 +0000 |
commit | fce301a6819bafa26446cd66bfd2f83f406970c6 (patch) | |
tree | e21ef1e7cfc5599c7c48b9cea137aed822d070d2 /Master/texmf-dist/tex/latex/easyformat | |
parent | 90919e4858ac87246e630dfa5b466c7ba336b8dd (diff) |
easyformat (29may17)
git-svn-id: svn://tug.org/texlive/trunk@44486 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/easyformat')
-rw-r--r-- | Master/texmf-dist/tex/latex/easyformat/easyformat.sty | 217 |
1 files changed, 104 insertions, 113 deletions
diff --git a/Master/texmf-dist/tex/latex/easyformat/easyformat.sty b/Master/texmf-dist/tex/latex/easyformat/easyformat.sty index 8279f8165b9..ca3f6db334e 100644 --- a/Master/texmf-dist/tex/latex/easyformat/easyformat.sty +++ b/Master/texmf-dist/tex/latex/easyformat/easyformat.sty @@ -19,197 +19,187 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% NOTE TO FUTURE: Italics correction works because of \maybe@ic. -% this macro might disappear in LaTeX3... +%% NOTE TO FUTURE: Italics correction works because of \maybe@ic, +% this macro might become \xfss_maybe_ic: in LaTeX3 % -% If the 'New Font Selection Scheme' would change, -% stuff WILL break... +% In LaTeX3 the `New Font Selection Scheme' is replaced +% by xfss (xfont). Moving will require some research. -%% TODO: Rewrite to use expl3 so it'll be easier to switch to LaTeX3. +%% WAIT! This package doesn't use the LaTeX3 naming conventions?! +% Yeah, since we make _ an active character, we can't. Sorry. %% Administration... -\NeedsTeXFormat{LaTeX2e} % Why no date? We'll leave that to the imports. -\ProvidesPackage{easyformat} - [2017/04/17 v1.2.0 Easily add boldface, italics and smallcaps.] - - -%% Import this handy package -\RequirePackage{ltxcmds}[2011/04/18] +\RequirePackage{expl3}[2015/11/11] +\ProvidesExplPackage + {easyformat} + {2017/05/28} + {1.3.0} + {Easily add boldface, italics and smallcaps.} %% Public macros % Add macros to switch the syntax on or off. -\newcommand*{\setundact}{ - \catcode`\_=\active +\cs_new:Npn \setundact { + \char_set_catcode_active:N {\_} } -\newcommand*{\setundsub}{ - \catcode`\_=8 +\cs_new:Npn \setundsub { + \char_set_catcode_math_subscript:N {\_} } -\newcommand*{\setciract}{ - \catcode`\^=\active +\cs_new:Npn \setciract { + \char_set_catcode_active:N {\^} } -\newcommand*{\setcirsup}{ - \catcode`\^=7 +\cs_new:Npn \setcirsup { + \char_set_catcode_math_superscript:N {\^} } -\newcommand*{\enableeasyformat}{ +\cs_new:Npn \enableeasyformat { \setundact \setciract } -\newcommand*{\disableeasyformat}{ +\cs_new:Npn \disableeasyformat { \setundsub \setcirsup } % Add macros which change the fontshape, fontseries and fontfamily. -\newcommand*{\setffamily}[1]{% - \fontfamily{#1}% - \selectfont% +\cs_new:Npn \setffamily #1 { + \fontfamily{#1} + \selectfont } -\newcommand*{\setfshape}[1]{% - \fontshape{#1}% - \selectfont% +\cs_new:Npn \setfshape #1 { + \fontshape{#1} + \selectfont } -\newcommand*{\setfseries}[1]{% - \fontseries{#1}% - \selectfont% +\cs_new:Npn \setfseries #1 { + \fontseries{#1} + \selectfont } % Add some macros which do small parts of what \normalfont does. % Were needed in v1.1.0 but let's keep them because they are useful :) -\newcommand*{\nrfamily}{% - \setffamily{\familydefault}% +\cs_new:Npn \nrfamily { + \setffamily {\familydefault} } -\newcommand*{\nrshape}{% - \setfshape{\shapedefault}% +\cs_new:Npn \nrshape { + \setfshape {\shapedefault} } -\newcommand*{\nrseries}{% - \setfseries{\seriesdefault}% +\cs_new:Npn \nrseries { + \setfseries {\seriesdefault} } % Add a macro LaTeX should have... -\newcommand*{\cir}{\string^\relax} +% The protected to fix the double superscript error. +\cs_new_protected:Npn \cir {\char_generate:nn {`^} {12}} -%% CONSTANTS +%% Constants & Variables % Yes I could use \sb and \sp but those are dependencies... -\let\EFOR@subscript=_ -\let\EFOR@superscript=^ - -% To test what style we're currently in. -\def\EFOR@it{it} -\def\EFOR@sc{sc} -\def\EFOR@bf{bx} +\tl_const:Nx \EFOR@subscript {\char_generate:nn {`_} {8}} +\tl_const:Nx \EFOR@superscript {\char_generate:nn {`^} {7}} % Remember the style before changing to italics/boldface/smallcaps. -\edef\EFOR@prev@shape@it{\shapedefault} % Used by italics. -\edef\EFOR@prev@shape@sc{\shapedefault} % Used by smallcaps. -\edef\EFOR@prev@series@bf{\seriesdefault} % Used by boldface. - - -%% UTILS -% So we can remove an unnecessary undescore when starting/stopping bold. -\newcommand*{\EFOR@util@removeChar}[1]{} - -% Do the first when in mathmode, the second if not. -\newcommand*{\EFOR@util@ifmmode}{% - \ifmmode - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi -} - -% Do the first when equal, the second if not (first or second of -% what comes _after_ \EFOR@util@ifx{...}{...} that is). -\newcommand*{\EFOR@util@ifx}[2]{% - \ifx#1#2\relax - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi -} +\str_new:N \EFOR@prev@shape@it +\str_new:N \EFOR@prev@shape@sc +\str_new:N \EFOR@prev@series@bf +\str_set:Nx \EFOR@prev@shape@it {\shapedefault} % Used by italics. +\str_set:Nx \EFOR@prev@shape@sc {\shapedefault} % Used by smallcaps. +\str_set:Nx \EFOR@prev@series@bf {\seriesdefault} % Used by boldface. %% Formating handling % Switch italics on or off. -\newcommand*{\EFOR@handle@italics}{% - \EFOR@util@ifx{\f@shape}{\EFOR@it} - {% - \setfshape{\EFOR@prev@shape@it}% - \edef\EFOR@prev@shape@it{\shapedefault}% +\cs_new:Npn \EFOR@handle@italics { + \str_if_eq:NNTF \f@shape \itdefault + { + \setfshape {\EFOR@prev@shape@it} + \str_set:Nx \EFOR@prev@shape@it {\shapedefault} % \maybe@ic adds italics correction if needed. % (might stop working in LaTeX3?) - \maybe@ic% - }{% - \edef\EFOR@prev@shape@it{\f@shape}% - \itshape% - }% + \maybe@ic + }{ + \str_set:Nx \EFOR@prev@shape@it {\f@shape} + \itshape + } } % Switch smallcaps on or off. -\newcommand*{\EFOR@handle@smallcaps}{% - \EFOR@util@ifx{\f@shape}{\EFOR@sc} - {% - \setfshape{\EFOR@prev@shape@sc}% - \edef\EFOR@prev@shape@sc{\shapedefault}% - }{% - \edef\EFOR@prev@shape@sc{\f@shape}% - \scshape% - }% +\cs_new:Npn \EFOR@handle@smallcaps { + \str_if_eq:NNTF \f@shape \scdefault + { + \setfshape {\EFOR@prev@shape@sc} + \str_set:Nx \EFOR@prev@shape@sc {\shapedefault} + }{ + \str_set:Nx \EFOR@prev@shape@sc {\f@shape} + \scshape + } } % Switch boldface on or off. -\newcommand*{\EFOR@handle@boldface}{% - \EFOR@util@ifx{\f@series}{\EFOR@bf} - {% - \setfseries{\EFOR@prev@series@bf}% - \edef\EFOR@prev@series@bf{\seriesdefault}% - }{% - \edef\EFOR@prev@series@bf{\f@series}% - \bfseries% - }% +\cs_new:Npn \EFOR@handle@boldface { + \str_if_eq:NNTF \f@series \bfdefault + { + \setfseries {\EFOR@prev@series@bf} + \str_set:Nx \EFOR@prev@series@bf {\seriesdefault} + }{ + \str_set:Nx \EFOR@prev@series@bf {\f@series} + \bfseries + } } +%% Aliases fo expl3 +% Make aliases for some LaTeX3 macros as _ isn't allowed later on. +\let\Expl@mode@if@math\mode_if_math:TF +\let\Expl@cs@gset@protected\cs_gset_protected:Npn +\let\Expl@peek@meaning@remove\peek_meaning_remove:NTF + + %% Activate the systems! -% Prepare the syntax in the preamble. +% First disable the Expl3 syntax as it will only cause trouble. +\ExplSyntaxOff + +% Now enable the easyformat syntax. \enableeasyformat % Now finally add the new syntax in the document part. \AtBeginDocument{ - % Just to be sure - \enableeasyformat + % We do not re-enable easyformat here, since that could + % cause unexpected behaviour. We tested if this causes errors. + + % NOTE: for some reason we have to use gset instead of new, no + % idea why though... % This is where the magic happens (also differentiates between % the text and math mode.) - % It is \protected because it should work in eg. \section{} - \protected\def_{\EFOR@util@ifmmode + % It is protected because it should work in eg. \section{} + + \Expl@cs@gset@protected_{\Expl@mode@if@math {\EFOR@subscript} - {\ltx@ifnextchar@nospace_ - % \EFOR@util@removeChar removes the second underscore. - {\EFOR@handle@boldface\EFOR@util@removeChar} + {\Expl@peek@meaning@remove_ + % The second underscore is removed when true. + {\EFOR@handle@boldface} {\EFOR@handle@italics}% }% } - \protected\def^{\EFOR@util@ifmmode + \Expl@cs@gset@protected^{\Expl@mode@if@math {\EFOR@superscript} {\EFOR@handle@smallcaps}% } } -% Cleanup + +%% Cleanup aka: Disable the systems! \AtEndDocument{ % Why no \def_\undefined and \def^\undefined? % Because if we use this syntax in eg. \section{}, @@ -219,12 +209,13 @@ %% DONE! -\endinput +% Unfortunately we can't add a \disableeasyformat here, +% since that breaks more stuff than it fixes... %% IMPLEMENTATION DETAILS: %% Why not \textit/bf/sc\bgroup and \egroup? -% Well actualy that was the original solution. Hwoever this +% Well actualy that was the original solution. However this % doesn't differentiate between ending itallics or ending % boldface. The current solution does and this makes the syntax % more predictable and generally more useful.
\ No newline at end of file |