Debian Codegraph @

texmf-dist/tex/latex/pictochrono/pictochrono.sty

raw
1 % Author : C. Pierquet
2 % licence : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt
3
4 \NeedsTeXFormat{LaTeX2e}
5 \ProvidesPackage{pictochrono}[2025/06/25 0.1.1 Inline chronometer, made with tikz]
6
7 %====HISTORY
8 % v 0.1.1 Strut option
9 % v 0.1.0 Initial version
10
11 %====BASE
12 \RequirePackage{tikz}
13 \usetikzlibrary{calc}
14 \RequirePackage{calc}
15 \RequirePackage{simplekv}
16 \RequirePackage{xstring}
17 \RequirePackage{etoolbox}
18
19 %====DIMENSIONS
20 \newlength{\tmp@chrono@hauteur@totale}
21 \newlength{\tmp@chrono@profondeur}
22 \newlength{\tmp@chrono@offset}
23
24 %====KEYS
25 \defKV[chronotikz]{Color=\def\colchrono{#1},Height=\def\hautchrono{#1},Delta=\def\deltachrono{#1},ColTime=\def\coltimechrono{#1},Offset=\def\raisechrono{#1},Strut=\def\strutchrono{#1}}
26 \setKVdefault[chronotikz]{Color=black,Height=auto,Delta=5,ColTime=lightgray,Offset=auto,Strut=qB}
27
28 %====INTERNAL MACRO
29 \newcommand\tmp@chrono@draw{%
30 \draw[\colchrono,line width={\echellechronotraits\tmp@chrono@hauteur@totale}] (0,0) circle[radius=1] ;
31 %rules
32 \filldraw[line width={\echellechronotraits\tmp@chrono@hauteur@totale},\colchrono,rounded corners={\echellechronoarrondis\tmp@chrono@hauteur@totale}] (65:1)--(65:1.15)--(57.5:1.15)--(57.5:1)--cycle ;
33 \filldraw[line width={\echellechronotraits\tmp@chrono@hauteur@totale},\colchrono,rounded corners={\echellechronoarrondis\tmp@chrono@hauteur@totale}] (115:1)--(115:1.15)--(122.5:1.15)--(122.5:1)--cycle ;
34 \filldraw[line width={\echellechronotraits\tmp@chrono@hauteur@totale},\colchrono,line join=round,rounded corners={\echellechronoarrondis\tmp@chrono@hauteur@totale}] (-0.1,1)--++(0,0.2)-|++(-0.15,0.15)--++(0.5,0)|-++(-0.15,-0.15)--++(0,-0.2)--cycle ;
35 }
36
37 %====MAIN MACRO
38 \NewDocumentCommand\pictochrono{ O{} m D<>{} }{%1:=options,2=durée,3=baseline tikz
39 \restoreKV[chronotikz]%
40 \setKV[chronotikz]{#1}%
41 %calcul des dimensions
42 \def\echellechronotraits{0.037}%
43 \def\echellechronoarrondis{0.003}%
44 \IfStrEqCase{\deltachrono}{%
45 {10}{\def\tmp@gen@traits{90,150,210,270,330,30}}%
46 {15}{\def\tmp@gen@traits{0,90,180,270}}%
47 {20}{\def\tmp@gen@traits{90,210,330}}%
48 {30}{\def\tmp@gen@traits{90,270}}%
49 }%
50 [\def\tmp@gen@traits{0,30,60,90,120,150,180,210,240,270,300,330}]%
51 %option tikz
52 \ifstrempty{#3}%
53 {%
54 \tikzset{chronoalign/.style={}}%
55 }%
56 {%
57 \IfStrEqCase{#3}{%
58 {vcenter}{\tikzset{chronoalign/.style={baseline=(current bounding box.center)}}}%
59 {vtop}{\tikzset{chronoalign/.style={baseline=(current bounding box.north)}}}%
60 {vbottom}{\tikzset{chronoalign/.style={baseline=(current bounding box.south)}}}%
61 }%
62 [\tikzset{chronoalign/.style={}}]%
63 }%
64 %hauteur auto ou non
65 \IfStrEq{\hautchrono}{auto}%
66 {%
67 \settototalheight{\tmp@chrono@hauteur@totale}{\hbox{\strutchrono}}%
68 \settodepth{\tmp@chrono@profondeur}{\hbox{\strutchrono}}%
69 \IfStrEq{\raisechrono}{auto}%
70 {%
71 \setlength{\tmp@chrono@offset}{-\tmp@chrono@profondeur}%
72 }%
73 {%
74 \setlength{\tmp@chrono@offset}{-\raisechrono}%
75 }%
76 %envt
77 \raisebox{\tmp@chrono@offset}{%
78 \begin{tikzpicture}[x={0.4125\tmp@chrono@hauteur@totale},y={0.4125\tmp@chrono@hauteur@totale},transform shape,chronoalign]
79 %time
80 \IfEq{#2}{}{}{\filldraw[rounded corners={\echellechronoarrondis\tmp@chrono@hauteur@totale},\coltimechrono,draw=none] (0,0)--({90-6*(#2)}:0.9) arc ({90-6*(#2)}:90:0.9)--cycle ;}%
81 %rules
82 \IfStrEq{\deltachrono}{0}%
83 {}%
84 {\foreach \i in \tmp@gen@traits {\draw[\colchrono,line width={\echellechronotraits\tmp@chrono@hauteur@totale}] (\i:0.6)--(\i:0.85);}}%
85 %clock
86 \tmp@chrono@draw
87 \end{tikzpicture}%
88 }%
89 }%
90 {%
91 \IfStrEq{\raisechrono}{auto}%
92 {%
93 \setlength{\tmp@chrono@offset}{0pt}%
94 }%
95 {%
96 \setlength{\tmp@chrono@offset}{\raisechrono}%
97 }%
98 \setlength{\tmp@chrono@hauteur@totale}{\hautchrono}%
99 \raisebox{\tmp@chrono@offset}{%
100 \begin{tikzpicture}[x={0.4125\tmp@chrono@hauteur@totale},y={0.4125\tmp@chrono@hauteur@totale},transform shape,chronoalign]
101 %time
102 \IfEq{#2}{}{}{\filldraw[rounded corners={\echellechronoarrondis\tmp@chrono@hauteur@totale},\coltimechrono,draw=none] (0,0)--({90-6*(#2)}:0.9) arc ({90-6*(#2)}:90:0.9)--cycle ;}%
103 %rules
104 \IfStrEq{\deltachrono}{0}%
105 {}%
106 {\foreach \i in \tmp@gen@traits {\draw[\colchrono,line width={\echellechronotraits\tmp@chrono@hauteur@totale}] (\i:0.6)--(\i:0.85);}}%
107 %clock
108 \tmp@chrono@draw
109 \end{tikzpicture}%
110 }%
111 }%
112 }
113
114 \endinput