diff options
author | Karl Berry <karl@freefriends.org> | 2012-07-13 17:56:30 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-07-13 17:56:30 +0000 |
commit | 75d256635dbdbe6b18ab0a72f3e4015120d6b2fb (patch) | |
tree | 83d7e4e0f3b2b69c5584947a76675e9e58b5d104 /Master/texmf-dist/tex/latex/embrac | |
parent | bab607b4b126505720438036b6390c01dec3d691 (diff) |
new latex package embrac (8jul12)
git-svn-id: svn://tug.org/texlive/trunk@27027 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/embrac')
-rw-r--r-- | Master/texmf-dist/tex/latex/embrac/embrac.sty | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/embrac/embrac.sty b/Master/texmf-dist/tex/latex/embrac/embrac.sty new file mode 100644 index 00000000000..a207abd7efc --- /dev/null +++ b/Master/texmf-dist/tex/latex/embrac/embrac.sty @@ -0,0 +1,284 @@ +% -------------------------------------------------------------------------- +% the EMBRAC package +% +% Upright Brackets in Emphasized Text +% +% -------------------------------------------------------------------------- +% Clemens Niederberger +% Web: https://bitbucket.org/cgnieder/embrac/ +% E-Mail: contact@mychemistry.eu +% -------------------------------------------------------------------------- +% Copyright 2012 Clemens Niederberger +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Clemens Niederberger. +% -------------------------------------------------------------------------- +% The embrac package consists of the files +% - embrac.sty, embrac_en.tex, embrac_en.pdf, embrac_kerning_test.tex and +% README +% -------------------------------------------------------------------------- +% > this package is strongly based on an article by Dominik Waßenhoven in +% > “Die TeXnische Komödie” 2 (2012), pp. 51--53 +% > which introduces code by Bruno Le Floch. Code parts and idea used with +% > their kind permission. Many thanks! +% -------------------------------------------------------------------------- +\RequirePackage { expl3 , xparse , l3keys2e } +\ProvidesExplPackage + {embrac} + {2012/06/29} + {0.1a} + {Upright Brackets in Emphasized Text} + +\bool_new:N \l_embrac_treat_biblatex_bool + +\keys_define:nn { embrac } + { biblatex .bool_set:N = \l_embrac_treat_biblatex_bool } + +% save original commands: +\cs_new_eq:Nc \embrac_orig_emph:n { emph~ } +\cs_generate_variant:Nn \embrac_orig_emph:n { V } + +\cs_new_eq:Nc \embrac_orig_textit:n { textit~ } +\cs_generate_variant:Nn \embrac_orig_textit:n { V } + +% preparations: +\cs_new_eq:NN \embrac_braces_format:n \textup +\cs_new_eq:NN \embrac_kern:n \skip_horizontal:n +\cs_new:Npn \embrac_empty_or_no_value:nTF #1#2#3 + { + \IfNoValueTF { #1 } { #2 } + { \tl_if_blank:nTF { #1 } { #2 } { #3 } } + } +\cs_new:Npn \embrac_empty_or_no_value:nF #1#2 + { + \IfNoValueF { #1 } + { \tl_if_blank:nF { #1 } { #2 } } + } + +% -------------------------------------------------------------------------- +% THE MAIN PART: +% storage of the tokens to be replaced: +\prop_new:N \l_embrac_emph_obrackets_prop +\prop_new:N \l_embrac_emph_obrackets_before_prop +\prop_new:N \l_embrac_emph_cbrackets_prop +\prop_new:N \l_embrac_emph_cbrackets_after_prop + +% do the replacing: +\cs_new:Npn \embrac_replace_brackets:N #1 + { + \prop_map_inline:Nn \l_embrac_emph_obrackets_prop + { + \tl_replace_all:Nnn #1 { ##1 } + { + \embrac_kern:n + { \prop_get:Nn \l_embrac_emph_obrackets_before_prop { ##1 } } + \embrac_braces_format:n { ##1 \embrac_kern:n { ##2 } } + } + } + \prop_map_inline:Nn \l_embrac_emph_cbrackets_prop + { + \tl_replace_all:Nnn #1 { ##1 } + { + \embrac_braces_format:n + { \embrac_kern:n { ##2 } ##1 } + \embrac_kern:n + { \prop_get:Nn \l_embrac_emph_cbrackets_after_prop { ##1 } } + } + } + } + +% internal \emph command: +\cs_new:Npn \embrac_emph:n #1 + { + \tl_set:Nn \l_tmpa_tl { #1 } + \embrac_replace_brackets:N \l_tmpa_tl + \embrac_orig_emph:V \l_tmpa_tl + } + +% internal \textit command: +\cs_new:Npn \embrac_textit:n #1 + { + \tl_set:Nn \l_tmpa_tl { #1 } + \embrac_replace_brackets:N \l_tmpa_tl + \embrac_orig_textit:V \l_tmpa_tl + } + +% biblatex compatibility: +\cs_new:Npn \embrac_treat_biblatex: + { + \bool_if:NT \l_embrac_treat_biblatex_bool + { + \embrac_replace_brackets:N \bibleftbracket + \embrac_replace_brackets:N \bibrightbracket + \embrac_replace_brackets:N \bibleftparen + \embrac_replace_brackets:N \bibrightparen + } + } + +% internal \emph command, second layer: +\cs_new_protected:Npn \embrac_new_emph:w #1#2 + { + \group_begin: + \embrac_treat_biblatex: + \IfBooleanTF { #1 } + { \embrac_orig_emph:n { #2 } } + { \embrac_emph:n { #2 } } + \group_end: + } + +% internal \textit command, second layer: +\cs_new_protected:Npn \embrac_new_textit:w #1#2 + { + \group_begin: + \embrac_treat_biblatex: + \IfBooleanTF { #1 } + { \embrac_orig_textit:n { #2 } } + { \embrac_textit:n { #2 } } + \group_end: + } + +% user command \emph: +\RenewDocumentCommand \emph { sm } + { \embrac_new_emph:w #1 { #2 } } + +% user command \textit: +\RenewDocumentCommand \textit { sm } + { \embrac_new_emph:w #1 { #2 } } + +% -------------------------------------------------------------------------- +% TURNING EMBRAC OFF AND ON: +% turning embrac off: +\NewDocumentCommand \EmbracOff {} + { + \cs_set_eq:NN \emph \embrac_orig_emph:n + \cs_set_eq:NN \textit \embrac_orig_textit:n + } + +% turning embrac on: +\NewDocumentCommand \EmbracOn {} + { + \cs_set_eq:NN \emph \embrac_new_emph:w + \cs_set_eq:NN \textit \embrac_new_textit:w + } + +% -------------------------------------------------------------------------- +% ADDING AND REMOVING BRACKETS: +% internal add command: +\cs_new:Npn \embrac_add_to_emph:nnnnnn #1#2#3#4#5#6 + { + \embrac_empty_or_no_value:nTF { #2 } + { \prop_put_if_new:Nnn \l_embrac_emph_obrackets_prop { #1 } { 0pt } } + { \prop_put_if_new:Nnn \l_embrac_emph_obrackets_prop { #1 } { #2 } } + \embrac_empty_or_no_value:nTF { #3 } + { \prop_put_if_new:Nnn \l_embrac_emph_obrackets_before_prop { #1 } { 0pt } } + { \prop_put_if_new:Nnn \l_embrac_emph_obrackets_before_prop { #1 } { #3 } } + \embrac_empty_or_no_value:nTF { #5 } + { \prop_put_if_new:Nnn \l_embrac_emph_cbrackets_prop { #4 } { 0pt } } + { \prop_put_if_new:Nnn \l_embrac_emph_cbrackets_prop { #4 } { #5 } } + \embrac_empty_or_no_value:nTF { #6 } + { \prop_put_if_new:Nnn \l_embrac_emph_cbrackets_after_prop { #4 } { 0pt } } + { \prop_put_if_new:Nnn \l_embrac_emph_cbrackets_after_prop { #4 } { #6 } } + } + +% internal delete command: +\cs_new:Npn \embrac_remove_from_emph:nn #1#2 + { + \prop_del:Nn \l_embrac_emph_obrackets_prop { #1 } + \prop_del:Nn \l_embrac_emph_obrackets_before_prop { #1 } + \prop_del:Nn \l_embrac_emph_cbrackets_prop { #2 } + \prop_del:Nn \l_embrac_emph_cbrackets_after_prop { #2 } + } + +% internal renew command: +\cs_new:Npn \embrac_renew_emph:nnnnnn #1#2#3#4#5#6 + { + \embrac_empty_or_no_value:nTF { #2 } + { \prop_put:Nnn \l_embrac_emph_obrackets_prop { #1 } { 0pt } } + { \prop_put:Nnn \l_embrac_emph_obrackets_prop { #1 } { #2 } } + \embrac_empty_or_no_value:nTF { #3 } + { \prop_put:Nnn \l_embrac_emph_obrackets_before_prop { #1 } { 0pt } } + { \prop_put:Nnn \l_embrac_emph_obrackets_before_prop { #1 } { #3 } } + \embrac_empty_or_no_value:nTF { #5 } + { \prop_put:Nnn \l_embrac_emph_cbrackets_prop { #4 } { 0pt } } + { \prop_put:Nnn \l_embrac_emph_cbrackets_prop { #4 } { #5 } } + \embrac_empty_or_no_value:nTF { #6 } + { \prop_put:Nnn \l_embrac_emph_cbrackets_after_prop { #4 } { 0pt } } + { \prop_put:Nnn \l_embrac_emph_cbrackets_after_prop { #4 } { #6 } } + } + +% internal change command: +\cs_new:Npn \embrac_change_emph:nnnnnn #1#2#3#4#5#6 + { + \prop_if_in:NnT \l_embrac_emph_obrackets_prop { #1 } + { + \embrac_empty_or_no_value:nF { #2 } + { \prop_put:Nnn \l_embrac_emph_obrackets_prop { #1 } { #2 } } + \embrac_empty_or_no_value:nF { #3 } + { \prop_put:Nnn \l_embrac_emph_obrackets_before_prop { #1 } { #3 } } + } + \prop_if_in:NnT \l_embrac_emph_cbrackets_prop { #4 } + { + \embrac_empty_or_no_value:nF { #5 } + { \prop_put:Nnn \l_embrac_emph_cbrackets_prop { #4 } { #5 } } + \embrac_empty_or_no_value:nF { #6 } + { \prop_put:Nnn \l_embrac_emph_cbrackets_after_prop { #4 } { #6 } } + } + } + +% user commands: +\NewDocumentCommand \AddEmph + { + m > { \SplitArgument { 1 } { , } } O{\NoValue,\NoValue} + m > { \SplitArgument { 1 } { , } } O{\NoValue,\NoValue} + } + { + \embrac_add_to_emph:nnnnnn { #1 } #2 { #3 } #4 + \ignorespaces + } + +\NewDocumentCommand \DeleteEmph { mm } + { + \embrac_remove_from_emph:nn { #1 } { #2 } + \ignorespaces + } + +\NewDocumentCommand \RenewEmph + { + m > { \SplitArgument { 1 } { , } } O{\NoValue,\NoValue} + m > { \SplitArgument { 1 } { , } } O{\NoValue,\NoValue} + } + { + \embrac_renew_emph:nnnnnn { #1 } #2 { #3 } #4 + \ignorespaces + } + +\NewDocumentCommand \ChangeEmph + { + m > { \SplitArgument { 1 } { , } } O{\NoValue,\NoValue} + m > { \SplitArgument { 1 } { , } } O{\NoValue,\NoValue} + } + { + \embrac_change_emph:nnnnnn { #1 } #2 { #3 } #4 + \ignorespaces + } + +% add some defaults: +\AddEmph{[}{]}[.04em,-.12em] +\AddEmph{(}[-.04em]{)}[,-.15em] + +\ProcessKeysOptions { embrac } + +\tex_endinput:D + +% HISTORY +2012/06/29 - v0.1 - first public release +2012/06/29 - v0.1a - renamed \RenewEmph => \ChangeEmph and added new \RenewEmph
\ No newline at end of file |