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 | |
parent | 90919e4858ac87246e630dfa5b466c7ba336b8dd (diff) |
easyformat (29may17)
git-svn-id: svn://tug.org/texlive/trunk@44486 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/latex/easyformat/easyformat.pdf | bin | 168134 -> 47204 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/easyformat/easyformat.tex | 42 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/easyformat/easyformat.sty | 217 |
3 files changed, 129 insertions, 130 deletions
diff --git a/Master/texmf-dist/doc/latex/easyformat/easyformat.pdf b/Master/texmf-dist/doc/latex/easyformat/easyformat.pdf Binary files differindex 472dac41f4e..94ebdff9d10 100644 --- a/Master/texmf-dist/doc/latex/easyformat/easyformat.pdf +++ b/Master/texmf-dist/doc/latex/easyformat/easyformat.pdf diff --git a/Master/texmf-dist/doc/latex/easyformat/easyformat.tex b/Master/texmf-dist/doc/latex/easyformat/easyformat.tex index 904680da685..78c8a0aa999 100644 --- a/Master/texmf-dist/doc/latex/easyformat/easyformat.tex +++ b/Master/texmf-dist/doc/latex/easyformat/easyformat.tex @@ -11,7 +11,7 @@ \def\easyformat{\texttt{easyformat}} \title{\easyformat\\[.5em] - \large _the_ manual for the 2017/04/17 version (v1.2.0)} + \large _the_ manual for the 2017/05/28 version (v1.3.0)} \author{Evert Provoost} @@ -22,7 +22,7 @@ \maketitle \begin{abstract} - \easyformat\ is a package that allows the use of~\_ to begin/end _italic_ or __bold__ and \cir\ to begin/end ^smallcaps^. As an alternative to the standard \LaTeXe\ \verb|\textit{italic}|, \verb|\textbf{bold}| and \verb|\textsc{smallcaps}|. + \easyformat\ is a package that allows the use of~\verb|_| to begin/end _italic_ or __bold__ and \verb|^| to begin/end ^smallcaps^. As an alternative to the standard \LaTeX\ \verb|\textit{italic}|, \verb|\textbf{bold}| and \verb|\textsc{smallcaps}|. \end{abstract} \tableofcontents @@ -80,9 +80,9 @@ \section{Usage, syntax and examples} Like usual you import the package with: \verb|\usepackage{easyformat}| - \easyformat\ makes \_ an active character, however it was already 'special' before so you still have to type~\verb|\_| if you want to insert an underscore. + \easyformat\ makes \verb|_| an active character, however it was already `special' before so you still have to type~\verb|\_| if you want to insert an underscore. - The same can be said of \cir, however since this one is difficult to add in ordinary \LaTeX, the \easyformat\ package gives you \verb|\cir| to get \cir. + The same can be said of \verb|^|, however since this one is difficult to add in ordinary \LaTeX, the \easyformat\ package gives you \verb|\cir| to get \cir. \newpage @@ -110,13 +110,15 @@ Those with a good eye might have noticed that \easyformat\ adds italics correction when needed. Just like \verb|\textit{zet}tim| would have. \section{Troubleshooting} + \easyformat\ tends to conflict with the loading of other packages, therefore you should probably load \easyformat\ last. + \begin{quotation} ``For some or other reason I get some weird formatting\dots'' \end{quotation} It could be a bug---in which case I'd love to hear from you (see \ref{contact})---however, you probably forgot to close your formatting somewhere and because of how \easyformat\ works you can get weird results. - %__Explanation:__ when you start eg. _italics_ with \_, \easyformat\ %remembers the shape (the same is true for ^smallcaps^, when you %start __boldface__ it remembers the series) of the font. When you %get out of _italics_, it resets the shape (respectively the series) %to what it was before the starting the formatting. + %__Explanation:__ when you start eg. _italics_ with \verb|_|, \easyformat\ %remembers the shape (the same is true for ^smallcaps^, when you %start __boldface__ it remembers the series) of the font. When you %get out of _italics_, it resets the shape (respectively the series) %to what it was before the starting the formatting. %% This is solved in version 2017/04/09 v1.1.0 @@ -131,12 +133,12 @@ % \hspace*{0pt}\verb|\setundact| %\end{quote} - %This first resets the \_ character so it can only be used as the start of %subscripts; then adds the subtitle and afterwards re-initiates \_ for %__bold__ and _italic_. (Obviously the \easyformat\ syntax does not work %_in_ the subtitle, so you'll have to use the \LaTeX-commands.) + %This first resets the \verb|_| character so it can only be used as the start of %subscripts; then adds the subtitle and afterwards re-initiates \verb|_| for %__bold__ and _italic_. (Obviously the \easyformat\ syntax does not work %_in_ the subtitle, so you'll have to use the \LaTeX-commands.) \section{Macros} \subsection{Special characters} \noindent\fbox{\texttt{\textbackslash cir}} - Add the circumflex (\cir) character. + Insert a circumflex (\cir) character. \subsection{Fonts} \noindent\fbox{\texttt{\textbackslash nrfamily}} @@ -164,21 +166,21 @@ \noindent\fbox{\texttt{\textbackslash disableeasyformat}} Disables the \easyformat\ syntax.\\ - \noindent\fbox{\texttt{\textbackslash setcaract}} - Sets the catcode of \cir\ to 13 (active).\\ + \noindent\fbox{\texttt{\textbackslash setciract}} + Sets the catcode of \verb|^| to 13 (active).\\ - \noindent\fbox{\texttt{\textbackslash setcarsup}} - Sets the catcode of \cir\ to 7 (superscript).\\ + \noindent\fbox{\texttt{\textbackslash setcirsup}} + Sets the catcode of \verb|^| to 7 (superscript).\\ \noindent\fbox{\texttt{\textbackslash setundact}} - Sets the catcode of \_ to 13 (active).\\ + Sets the catcode of \verb|_| to 13 (active).\\ \noindent\fbox{\texttt{\textbackslash setundsub}} - Sets the catcode of \_ to 8 (subscript). + Sets the catcode of \verb|_| to 8 (subscript). \section{Technical details} - \subsection{Why \_ and not *?\label{Why?!}} - To make * work we would have to make it an active character, however this would break things like \verb|\section*{Art}|. The~\_ is already protected by \TeX\ because of it's meaning in mathmode. However, it has little to no use in textmode. This is why we can use~\_ for this purpose and not~*. + \subsection{Why \texttt{\_} and not *?\label{Why?!}} + To make * work we would have to make it an active character, however this would break things like \verb|\section*{Art}|. The~\verb|_| is already protected by \TeX\ because of it's meaning in mathmode. However, it has little to no use in textmode. This is why we can use~\verb|_| for this purpose and not~*. \subsection{Does this break mathmode?} No it doesn't. It keeps behaving like before in mathmode, it's meaning only changes in textmode. (We first check whether we are in mathmode or not and behave accordingly.) @@ -190,8 +192,15 @@ \section{Changelog} We only include important changes from v1.0.0 onwards, since earlier versions barely worked. + \subsection*{2017/05/28 v1.3.0} + Removed forced re-enabling of the \easyformat-syntax at the start of the document. + Rewritten to use \texttt{expl3}, this makes the code shorter and a future move to \LaTeX3 easier. + Fixed an error that could occur with \verb|\cir|. + \easyformat\ now also behaves correctly when a fontpackage is loaded. + \subsection*{2017/04/17 v1.2.0} - Improved handling of mixed styles. Added \verb|^smallcaps^| for ^smallcaps^. + Improved handling of mixed styles. + Added \verb|^smallcaps^| for ^smallcaps^. \subsection*{2017/04/09 v1.1.0} Made usage of syntax in \verb|\section{}|, and similar macros, possible. Changed the behaviour so it works more like \verb|\emph{}| (this also simplifies the code). @@ -199,7 +208,6 @@ \subsection*{2017/04/07 v1.0.0} First stable version. - % Insert a friendly message :) \vspace*{\fill}\noindent Made with $\heartsuit$ in Berlaar, Belgium. 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 |