summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/edichokey/edichokey.sty
blob: 1b927eadaf7df267fe9e9cfdb8f9e87b49ba5047 (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
%% edichokey.sty
%% Copyright 2017--2020 Yuchang Yang < yang.yc.allium@gmail.com >
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% 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.3c 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 Yuchang Yang.
%
% This work consists of:
%   - the style file: [edichokey.sty];
%   - the manual files: [edichokey-doc-en.tex, edichokey-doc-en.pdf, README.md];
%   - the example files: [edichokey-ex.tex, edichokey-ex.pdf].
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{edichokey}[2020/07/14 v2.00 package edichokey]
\makeatletter
\def\edk@get@array#1{\csname edk@array@#1\endcsname}
\def\edk@set@array#1#2{\expandafter\xdef\csname edk@array@#1\endcsname{#2}}
\newif\if@edk@named@
\newdimen\alterindent\alterindent1.2em
\newdimen\taxonrightskip\taxonrightskip2em
\newdimen\edk@leftskip
\newbox\edk@header
\newcount\edk@depth
\newcount\edk@couplet
\def\edknamestyle{\bfseries\itshape}
\def\edk@prefix{}
\def\@take@bracket[#1]{\def\edk@prefix{#1\unskip\space}}
\def\@take@brace#1{\@take@bracket[#1]}
\def\@take@arg{%
  \ifx\@next@token[%]
    \let\temp@\@take@bracket
  \else
    \ifx\@next@token\bgroup%\egroup
      \let\temp@\@take@brace
    \else
      \let\temp@\relax
    \fi
  \fi
  \temp@}
\def\take@arg{\futurelet\@next@token\@take@arg}
\def\dot@fill#1{\leavevmode\leaders\hb@xt@.44em{\hss.\hss}\hskip#1\kern\z@}
\def\dot@line{%
  \unskip\dot@fill{0pt plus 1fil}\penalty150%
  \null\nobreak\dot@fill{12pt plus 1fill}}
\newenvironment{Key}
  {\edk@depth\z@
  \edk@couplet\z@
  \parindent\z@
  \advance\rightskip\taxonrightskip
  \edk@leftskip\dimexpr\leftskip-\alterindent\relax
  \global\@edk@named@false
  \take@arg
  }{\par}
\def\name@#1{%
  \global\@edk@named@true
  \dot@line
  \mbox{\edknamestyle\edk@prefix#1}%
  \kern-\taxonrightskip\par}
\def\name@@[#1]#2{%
  {\@take@bracket[#1]\name@{#2}}}
\def\name{%
  \@ifnextchar[%]
  \name@@\name@}
\def\alter{%
  \par
  \if@edk@named@
    \@whilenum\edk@get@array{\the\edk@depth}=\z@\do{%
      \advance\edk@depth-\@ne}%
    \xdef\edk@number{\edk@get@array{\the\edk@depth}}%
    \edk@set@array{\the\edk@depth}{0}%
  \else
    \advance\edk@couplet\@ne
    \advance\edk@depth\@ne
    \xdef\edk@number{\the\edk@couplet}%
    \edk@set@array{\the\edk@depth}{\the\edk@couplet}%
  \fi
  \@edk@named@false
  \sbox\edk@header{\edk@number.~}%
  \leftskip\dimexpr\edk@leftskip+\edk@depth\alterindent+\wd\edk@header\relax
  \indent\llap{\box\edk@header}}  
\makeatother