summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/interfaces/interfaces-truncate.sty
blob: d3e3c069d447d520967367c74bee636d6224cd8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
%%
%% This is file `interfaces-truncate.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% interfaces.dtx  (with options: `truncate')
%% 
%% This is a generated file.
%% 
%% interfaces : 2010/11/21 v2.3 - interfaces : interfaces with keys for other packages (FC)
%% 
%% 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
%% 
%% This work consists of the main source file interfaces.dtx
%% and the derived files
%%     interfaces.sty, interfaces.pdf, interfaces.ins,
%%     interfaces-base.sty,
%%     interfaces-LaTeX.sty,
%%     interfaces-tikz.sty,
%%     interfaces-titlesec.sty,
%%     interfaces-hyperref.sty,
%%     interfaces-bookmark.sty,
%%     interfaces-hypbmsec.sty,interfaces-hypbmsec.code.tex,
%%     interfaces-fancyhdr.sty,
%%     interfaces-marks.sty,
%%     interfaces-tocloft.sty,
%%     interfaces-makecell.sty,
%%     interfaces-enumitem.sty,
%%     interfaces-truncate.sty,
%%     interfaces-appendix.sty,
%%     interfaces-embedfile.sty,
%%     interfaces-environ.sty,
%%     interfaces-umrand.sty,
%%     interfaces-scrlfile.sty,
%%     interfaces-pgfkeys.sty,
%%     interfaces-etoolbox.sty
%% 
%% interfaces: interfaces with keys for other packages (FC)
%% Copyright (C) 2010 by Florent Chervet <florent.chervet@free.fr>
%% 
\ProvidesPackage{interfaces-truncate}
\newrobustcmd\trunctext[3][\TruncateMarker]{% do nothing if width of #3 is less than #2
   \begingroup
      \hbadness\maxdimen\hfuzz\vsize
      \setbox\z@=\hbox to\dimexpr#2\relax{\ignorespaces#3\unskip}%
      \ifnum\badness>\@M
            \def\next{\truncate[{#1}]{#2}{#3}}%
      \else \def\next{#3}%
      \fi
      \expandafter\endgroup\next
}% \trunctext
\newrobustcmd\htruncadjust[1]{\@testopt
   {\itf@htruncadjust{#1}}{}%
}% \htruncadjust
\long\def\itf@htruncadjust#1[#2]#3{%#1=total width, #2=[x_1..x_n], #3=text_1..text_n
   \begingroup
   \let\itf@trunc@width\@empty
   \let\itf@istruncated\@gobble % to remove the first comma
   \let\the@dimen\relax
   \count@\z@  \dimen@\z@
   \ifblank{#2}% no optional [x_1,...,x_n] parameters
      {%
         \@for\x:=#3\do{%
            \advance \count@ \@ne
            \setbox\z@=\hbox{\ignorespaces\x\unskip}%
            \dimen\count@ = \wd\z@
            \toks\count@\expandafter{\the\dimen\count@}%
            \advance\dimen@ \dimen\count@}%
      }
      {%
         \@for\x:=#2\do{%
            \advance \count@ \@ne
            \toks\count@\expandafter{\x\p@}%
            \advance\dimen@ \x\p@
            \dimen\count@ -\@ne\p@}%
      }%
   \advance\count@\@ne \dimendef\itf@freespace=\count@
   \advance\count@\@ne \dimendef\itf@tempdim=\count@
   \advance\count@\@ne \dimendef\itf@sum=\count@
   \count@\z@
   \itf@freespace\z@ % free space left when   w_i < x_i/sum(x_i) * total
   \@for\x:=#3\do{%
      \advance \count@ \@ne
      \ifdim \dimen\count@<\z@ % not measured before
            \setbox\z@=\hbox{\ignorespaces\x\unskip}%
            \dimen\count@ = \wd\z@
      \fi
      \itf@tempdim = \itf@scaledimen{#1}*\the\toks\count@/\dimen@\relax
      \ifdim \dimen\count@ > \itf@tempdim
            \dimen\count@ = \itf@tempdim
            \edef\itf@istruncated{\itf@istruncated,\the\count@}%
            \advance\itf@sum by\the\toks\count@
      \else
         \advance\itf@freespace \itf@tempdim
         \advance\itf@freespace -\dimen\count@
      \fi
      \edef\itf@trunc@width{\itf@trunc@width\the\count@{\the@dimen\the\count@}}%
   }%
%%   Free space=\the\itf@freespace\par
   \ifdim\itf@freespace > \z@ % reinsert free space proportionally
      \ifx\itf@istruncated\@gobble\else
      \@for\x:=\itf@istruncated\do{%
         \advance\dimen\x by\itf@scaledimen\itf@freespace*\the\toks\x/\itf@sum\relax
      }%
   \fi\fi
   \def\the@dimen{\the\dimen}%
   \edef\itf@trunc@width{\itf@trunc@width}%
   \expandafter\endgroup
      \expandafter\def
         \expandafter\itf@trunc@width
               \expandafter{\itf@trunc@width}%
%%   total=\the\dimexpr#1\relax
}% \itf@htruncadjust
\def\itf@scalefactor#1#2{\strip@pt\dimexpr#1*65536/#2\relax}
\def\itf@scaledimen#1*#2/#3\relax{%
   \dimexpr\itf@scalefactor{#2}{#3}\dimexpr#1\relax\relax
}% \itf@scaledimen
\newcommand*\htruncwidth[1]{% purely expandable
   \expandafter\itf@htruncwidth\itf@trunc@width\relax\relax\@nnil{#1}%
}% \htruncwidth
\def\itf@htruncwidth#1#2#3\@nnil#4{%
   \ifx\relax#1\itf@trunc@nosuchwidth{#4}%
   \else\ifnum#1=#4
      #2%
   \else
      \itf@htruncwidth#3\@nnil{#4}%
   \fi\fi
}% \itf@htruncwidth
\def\itf@trunc@nosuchwidth#1{%
   \PackageError{interfaces-truncate}
      {You requested the width for text nr#1
      \MessageBreak but there is no such text
      \MessageBreak Therefore no such width!}\@ehd
}% \itf@trunc@nosuchwidth
\endinput
%%
%% End of file `interfaces-truncate.sty'.