diff options
author | Karl Berry <karl@freefriends.org> | 2017-04-17 22:26:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-04-17 22:26:09 +0000 |
commit | f0f5600c20467be8d19a1fc45b61463c26718ebe (patch) | |
tree | 137bdfc893ecc10b5b5033e58b33b71bb2a31954 /Master/texmf-dist/tex/latex/easyformat | |
parent | a367543b300faf3092d5847d0b107c4dab768cfe (diff) |
easyformat (17apr17)
git-svn-id: svn://tug.org/texlive/trunk@43901 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 | 162 |
1 files changed, 120 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/latex/easyformat/easyformat.sty b/Master/texmf-dist/tex/latex/easyformat/easyformat.sty index 922d09abd46..8279f8165b9 100644 --- a/Master/texmf-dist/tex/latex/easyformat/easyformat.sty +++ b/Master/texmf-dist/tex/latex/easyformat/easyformat.sty @@ -1,35 +1,38 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% easyformat Adds easier bolds and italics to LaTeX. % -% Copyright (C) 2017 Evert Provoost <evert.provoost@gmail.com> % -% % -% This program is free software: you can redistribute it and/or modify % -% it under the terms of the GNU General Public License as published by % -% the Free Software Foundation, either version 3 of the License, or % -% (at your option) any later version. % -% % -% This program is distributed in the hope that it will be useful, % -% but WITHOUT ANY WARRANTY; without even the implied warranty of % -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % -% GNU General Public License for more details. % -% % -% You should have received a copy of the GNU General Public License % -% along with this program. If not, see <http://www.gnu.org/licenses/>. % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% easyformat Easily add boldface, italics and smallcaps in LaTeX. % +% Copyright (C) 2017 Evert Provoost <evert.provoost@gmail.com> % +% % +% This program is free software: you can redistribute it and/or modify % +% it under the terms of the GNU General Public License as published by % +% the Free Software Foundation, either version 3 of the License, or % +% (at your option) any later version. % +% % +% This program is distributed in the hope that it will be useful, % +% but WITHOUT ANY WARRANTY; without even the implied warranty of % +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % +% GNU General Public License for more details. % +% % +% You should have received a copy of the GNU General Public License % +% along with this program. If not, see <http://www.gnu.org/licenses/>. % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% NOTE TO FUTURE: Italics correction works because of \maybe@ic. % this macro might disappear in LaTeX3... % -% If the New Font Selection Scheme would change, +% If the 'New Font Selection Scheme' would change, % stuff WILL break... +%% TODO: Rewrite to use expl3 so it'll be easier to switch to LaTeX3. + + %% Administration... \NeedsTeXFormat{LaTeX2e} % Why no date? We'll leave that to the imports. \ProvidesPackage{easyformat} - [2017/04/09 v1.1.0 Adds easier bolds and italics.] + [2017/04/17 v1.2.0 Easily add boldface, italics and smallcaps.] %% Import this handy package @@ -46,26 +49,73 @@ \catcode`\_=8 } +\newcommand*{\setciract}{ + \catcode`\^=\active +} + +\newcommand*{\setcirsup}{ + \catcode`\^=7 +} + +\newcommand*{\enableeasyformat}{ + \setundact + \setciract +} + +\newcommand*{\disableeasyformat}{ + \setundsub + \setcirsup +} + +% Add macros which change the fontshape, fontseries and fontfamily. +\newcommand*{\setffamily}[1]{% + \fontfamily{#1}% + \selectfont% +} + +\newcommand*{\setfshape}[1]{% + \fontshape{#1}% + \selectfont% +} + +\newcommand*{\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}% +} + \newcommand*{\nrshape}{% - \fontshape{\shapedefault}% - \selectfont% + \setfshape{\shapedefault}% } \newcommand*{\nrseries}{% - \fontseries{\seriesdefault}% - \selectfont% + \setfseries{\seriesdefault}% } +% Add a macro LaTeX should have... +\newcommand*{\cir}{\string^\relax} + %% CONSTANTS -% Yes I could use \sb but that is a dependency... +% 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} +% 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. @@ -81,7 +131,7 @@ } % Do the first when equal, the second if not (first or second of -% what comes *after* \EFOR@util@ifx{...}{...} that is). +% what comes _after_ \EFOR@util@ifx{...}{...} that is). \newcommand*{\EFOR@util@ifx}[2]{% \ifx#1#2\relax \expandafter\@firstoftwo @@ -93,30 +143,53 @@ %% Formating handling % Switch italics on or off. -\newcommand*{\EFOR@handle@italic}{% +\newcommand*{\EFOR@handle@italics}{% \EFOR@util@ifx{\f@shape}{\EFOR@it} - % \maybe@ic adds italics correction if needed. - % (might stop working in LaTeX3?) - {\nrshape\maybe@ic} - {\itshape}% + {% + \setfshape{\EFOR@prev@shape@it}% + \edef\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% + }% +} + +% 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% + }% } % Switch boldface on or off. -\newcommand*{\EFOR@handle@bold}{% +\newcommand*{\EFOR@handle@boldface}{% \EFOR@util@ifx{\f@series}{\EFOR@bf} - {\nrseries} - {\bfseries}% + {% + \setfseries{\EFOR@prev@series@bf}% + \edef\EFOR@prev@series@bf{\seriesdefault}% + }{% + \edef\EFOR@prev@series@bf{\f@series}% + \bfseries% + }% } %% Activate the systems! % Prepare the syntax in the preamble. -\setundact +\enableeasyformat % Now finally add the new syntax in the document part. \AtBeginDocument{ % Just to be sure - \setundact + \enableeasyformat % This is where the magic happens (also differentiates between % the text and math mode.) @@ -125,18 +198,23 @@ {\EFOR@subscript} {\ltx@ifnextchar@nospace_ % \EFOR@util@removeChar removes the second underscore. - {\EFOR@handle@bold\EFOR@util@removeChar} - {\EFOR@handle@italic}% + {\EFOR@handle@boldface\EFOR@util@removeChar} + {\EFOR@handle@italics}% }% } + + \protected\def^{\EFOR@util@ifmmode + {\EFOR@superscript} + {\EFOR@handle@smallcaps}% + } } % Cleanup \AtEndDocument{ - % Why no \def_\undefined? + % Why no \def_\undefined and \def^\undefined? % Because if we use this syntax in eg. \section{}, % the macro should still work in the .aux file... - \setundsub + \disableeasyformat } @@ -145,7 +223,7 @@ %% IMPLEMENTATION DETAILS: -%% Why not \textit/bf\bgroup and \egroup? +%% Why not \textit/bf/sc\bgroup and \egroup? % Well actualy that was the original solution. Hwoever this % doesn't differentiate between ending itallics or ending % boldface. The current solution does and this makes the syntax |