summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-07-03 22:05:09 +0000
committerKarl Berry <karl@freefriends.org>2015-07-03 22:05:09 +0000
commit229926b078d21f35d3d6a5e2c42449f15fbeeca6 (patch)
tree7d82706a77c53c35a4ead2e2bda686b500ac861c /Master/texmf-dist/tex
parent7bccd1325cbbedb9f5352aabe50e75d0c1f20cca (diff)
bidihl (3jul15)
git-svn-id: svn://tug.org/texlive/trunk@37746 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/xelatex/bidihl/bidihl.sty173
1 files changed, 173 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/xelatex/bidihl/bidihl.sty b/Master/texmf-dist/tex/xelatex/bidihl/bidihl.sty
new file mode 100644
index 00000000000..ff1dc66284c
--- /dev/null
+++ b/Master/texmf-dist/tex/xelatex/bidihl/bidihl.sty
@@ -0,0 +1,173 @@
+%%
+%% This is file `bidihl.sty'.
+%%
+%% ___________________________________________
+%% Copyright © 2015 Vafa Khalighi <persian-tex@tug.org>
+%%
+%% It may be distributed and/or modified under the LaTeX Project Public License,
+%% version 1.3c or higher (your choice). The latest version of
+%% this license is at: http://www.latex-project.org/lppl.txt
+%%
+%% This work is “author-maintained” (as per LPPL maintenance status)
+%% by Vafa Khalighi.
+%%
+%%
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{bidihl}[2015/07/02 v0.1a Experimental bidi-aware text highlighting]
+
+%% Load color package and define highlighting color
+
+\RequirePackage{color}
+\definecolor{bidihlcolor}{rgb}{1,1,0} % yellow
+
+%% Register Declaration
+
+\newdimen\bidihl@highlight@depth \bidihl@highlight@depth-\maxdimen
+\newdimen\bidihl@highlight@thickness \bidihl@highlight@thickness.4pt
+
+\newdimen\bidihlboxheight \bidihlboxheight10pt
+
+\newdimen\bidihlspacerulewidth \bidihlspacerulewidth0.1pt
+
+\newdimen\bidihl@height \newdimen\bidihl@depth
+
+\newcount\bidihl@spacefactor
+
+\newif\ifbidihl@nospace
+
+%% User Interface and Initialization
+
+\def\bidihl{\bidihl@highlight\bidihl@highlight@depth{-\bidihl@highlight@depth}{-\dp\strutbox}}
+
+
+\def\bidihl@highlight#1#2#3#4{\begingroup \let\\\bidihlnewline
+ \ifdim#1<\z@ \bidihl@height#3\relax
+ \else \bidihl@height#2\relax \fi
+ \bidihl@depth-\bidihl@height
+ \ifdim\bidihl@height<\z@ \advance\bidihl@depth\bidihl@highlight@thickness
+ \else \advance\bidihl@height\bidihl@highlight@thickness \fi
+ \bidihl@nospacetrue
+ \ifvmode\leavevmode\fi \bidihl@spacefactor\spacefactor
+ \def\@tempa{#4 }\edef\@tempb{\noexpand\@nil\space}%
+ \expandafter\expandafter\expandafter\bidihl@wordloop
+ \expandafter\@tempa\@tempb
+ \endgroup \bidihl@aftergroup}
+
+
+%% Processing Word Elements
+
+\def\bidihl@wordloop{\bidihl@ifbgroup\bidihl@wordblock\bidihl@iwordloop}
+\def\bidihl@ifbgroup#1#2{\let\@tempa#1\let\@tempb#2\futurelet\@tempc\bidihl@ifnc}
+\def\bidihl@ifnc{\ifx\@tempc\bgroup \let\next\@tempa \else\let\next\@tempb \fi
+ \next}
+\def\bidihl@wordblock#1{\bidihl@spaceskip
+ \def\bidihl@theword{#1}\bidihl@putword \bidihl@nospacetrue
+ \bidihl@wordloop}
+\def\bidihl@iwordloop#1 {\def\@tempa{#1}\ifx\@tempa\@nnil \let\next\bidihl@end
+ \else\ifx\@tempa\empty \else
+ \bidihl@spaceskip
+ \def\bidihl@theword{}\bidihl@charloop#1\@nil\fi
+ \bidihl@nospacefalse \let\next\bidihl@wordloop \fi
+ \next}
+
+\def\bidihl@charloop{\bidihl@ifbgroup\bidihl@charblock\bidihl@icharloop}
+\def\bidihl@charblock#1{\bidihl@putword
+ \def\bidihl@theword{#1}\bidihl@putword
+ \bidihl@charloop}
+\def\bidihl@icharloop#1{\def\@tempa{#1}%
+ \ifx\@tempa\@nnil \bidihl@putword \let\next\relax
+ \else\ifx\bidihlspace#1\relax \bidihl@putword \let\next\bidihl@space
+ \else\ifx\bidihlnewline#1\relax \bidihl@putword \let\next\bidihl@newline
+ \else\edef\bidihl@theword{\bidihl@theword#1}%
+ \let\next\bidihl@charloop \fi\fi\fi \next}
+\def\bidihlspace{\PackageError{bidihl}%
+ {\string\bidihlspace\space cannot be used here.}%
+ {\string\bidihlspace\space can be used only in the argument of
+ \string\bidihl.}}
+\def\bidihlnewline{\PackageError{bidihl}%
+ {\string\bidihlnewline\space cannot be used here.}%
+ {\string\bidihlnewline\space can be used only in the argument of
+ \string\bidihl.}}
+
+%% Interword Spacing
+
+\def\bidihl@spaceskip{\ifbidihl@nospace\else
+ \ifdim\spaceskip=\z@
+ \@tempdima\fontdimen3\font\relax
+ \multiply\@tempdima\bidihl@spacefactor \divide\@tempdima\@m
+ \@tempdimb\fontdimen4\font\relax \multiply\@tempdimb\@m
+ \divide\@tempdimb\bidihl@spacefactor
+ \@tempskipa\fontdimen2\font plus\@tempdima minus\@tempdimb\relax
+ \else
+ \edef\@tempa{\the\spaceskip\space @ @ @ @ }%
+ \expandafter\bidihl@setspaceskip\@tempa\@nil
+ \fi
+ \ifnum\bidihl@spacefactor<2000\else
+ \ifdim\xspaceskip=\z@ \advance\@tempskipa\fontdimen7\font
+ \else \@tempskipa\xspaceskip
+ \fi\fi
+ \bidihl@skip\@tempskipa \fi}
+\def\bidihl@setspaceskip#1 #2 #3 #4 #5 #6\@nil{\@tempdima\z@ \@tempdimb\z@
+ \def\@tempa{#2}\def\@tempb{#3}%
+ \ifx\@tempa\bidihl@plus \@tempdima#3\def\@tempa{#4}\def\@tempb{#5}\fi
+ \ifx\@tempa\bidihl@minus \@tempdimb\@tempb\relax\fi
+ \multiply\@tempdima\bidihl@specefactor \divide\@tempdima\@m
+ \multiply\@tempdimb\@m \divide\bidihl@spacefactor
+ \@tempskipa#1 plus\@tempdima minus\@tempdimb\relax}
+\def\@tempa#1 #2 #3 #4 #5\@nil{\def\bidihl@plus{#2}\def\bidihl@minus{#4}}
+\@tempskipa1pt plus 2pt minus 3pt
+\expandafter\@tempa\the\@tempskipa\@nil
+
+
+
+%% Draw highlight text
+
+\def\bidihl@putword{\setbox\@tempboxa\hbox{\bidihl@theword
+ \global\bidihl@spacefactor\spacefactor}%
+ \@tempdima\wd\@tempboxa
+ \if@RTL%
+ \box\@tempboxa
+ {\color{bidihlcolor}\llap{\vrule\@height\bidihlboxheight\@depth\bidihl@depth\@width\@tempdima}}%
+ \else
+ {\color{bidihlcolor}\rlap{\vrule\@height\bidihlboxheight\@depth\bidihl@depth\@width\@tempdima}}%
+ \box\@tempboxa
+ \fi
+ \def\bidihl@theword{}}
+\def\bidihl@skip#1{%
+ \leaders\hbox{{\color{bidihlcolor}\vrule\@height\bidihlboxheight\@depth\bidihl@depth\@width\bidihlspacerulewidth}}\hskip#1\relax}
+
+
+
+%% Explicit Spacing and Line Breaking
+
+\def\bidihl@space{\@ifstar\bidihl@sspace\bidihl@ispace}
+\def\bidihl@sspace#1{\vrule width\z@\nobreak\bidihl@skip{#1}\bidihl@charloop}
+\def\bidihl@ispace#1{\@tempskipa#1\relax
+ \@ifstar{\@tempswafalse\bidihl@iispace}{\@tempswatrue\bidihl@iispace}}
+\def\bidihl@iispace{\@ifnextchar[%]
+ {\bidihl@penalty}%
+ {\bidihl@skip\@tempskipa \bidihl@charloop}}
+\def\bidihl@penalty[#1]{\@tempcnta#1\relax
+ \if@tempswa
+ \ifnum\@tempcnta<\z@ \@tempcnta-\@tempcnta \fi
+ \ifcase\@tempcnta \or
+ \@tempcnta\@lowpenalty \or
+ \@tempcnta\@medpenalty \or
+ \@tempcnta\@highpenalty \else
+ \@tempcnta\@M \fi
+ \ifnum#1<\z@ \@tempcnta-\@tempcnta \fi \fi
+ \penalty\@tempcnta \bidihl@skip\@tempskipa \bidihl@charloop}
+
+\def\bidihl@newline{\@ifstar{\bidihl@skip{0pt plus1fil}\break \bidihl@charloop}%
+ {\hfil \break \bidihl@charloop}}
+
+
+
+
+
+%% Finalization
+
+\def\bidihl@end{\xdef\bidihl@aftergroup{\spacefactor\number\bidihl@spacefactor\relax}}
+\endinput
+%%
+%% End of file `bidihl.sty'. \ No newline at end of file