/
showyourwork.sty
215 lines (200 loc) · 6.44 KB
/
showyourwork.sty
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{showyourwork}[2021/07/07 Open source science articles]
% Imports
\RequirePackage{mathtools} % equation tags
\RequirePackage{xcolor} % custom colors
\RequirePackage{hyperref} % url links
\RequirePackage{suffix} % allows definition of starred commmands
\RequirePackage{ifxetex}
\ifxetex
\RequirePackage{fontspec}
\defaultfontfeatures{Extension = .otf}
\fi
\RequirePackage{fontawesome5} % FontAwesome symbols
\RequirePackage{letltxmacro} % command redefinitions
\RequirePackage{xstring} % string manipulation
\RequirePackage{catchfile} % read file into macro
\RequirePackage{totcount} % count total number of errors
\RequirePackage[notref, notcite]{showkeys} % get label refs
\RequirePackage{marginnote} % margin notes
\RequirePackage{xspace} % better spacing after icons
\RequirePackage{graphicx} % includegraphics
\RequirePackage{stackengine} % stacking figure links
\newcommand{\showyourwork}{%
\href{https://github.com/rodluger/showyourwork}%
{\raisebox{-1.3ex}{\includegraphics[width=7em]{showyourwork.pdf}}}\hspace{0.2em}%
}
% Generic: replace \LaTeX with \Latex + showyourwork in \maketitle
\let\oldmaketitle\maketitle
\def\maketitle{%
\let\oldLaTeX\LaTeX
\def\LaTeX{\oldLaTeX/\showyourwork}
\oldmaketitle
\let\LaTeX\oldLaTeX
}
% MNRAS hack for displaying showyourwork logo
\@ifclassloaded{mnras}{
\ifx\CUP@mtlplain@loaded\undefined
\def\@printed{Preprint \tod@y\
\qquad\qquad\qquad Compiled using \showyourwork/MNRAS \LaTeX\ style file v\@version}
\else
\def\@printed{}
\fi
}{}
% A&A hack for displaying showyourwork logo + abstract links
\@ifclassloaded{aa}{
\renewcommand*\aa@manuscriptname{%
\LaTeX
\hspace{\stretch{1}}%
\smash{\stackunder[0.5em]{\copyright ESO \the\year}{%
\href{((- repo.url -))/tree/((- repo.sha -))/}{%
\color{((- status -))}%
\faGithub%
}%
((* if CI *))
\hspace{3pt}%
\href{((- repo.url -))/actions/runs/((- run_id -))/}{%
\color{sywGreen}%
\faCheckCircle%
}%
((* endif *))
}
}
}
}{}
% Logging
\newwrite\syw@LogFile
\immediate\openout\syw@LogFile=showyourwork.log
\newcommand\syw@LogMessage[1]{%
\protected@write
\syw@LogFile
{\let\tmp\write\def\write{\immediate\tmp}}%
{#1}%
}
\syw@LogMessage{This is showyourwork ((- version -)).}
% Custom margin icon
\newcommand\marginicon[1]{
\renewcommand\showkeyslabelformat[1]{#1}%
}
% Define custom colors
\definecolor{sywRed}{rgb}{0.80,0.14,0.19}
\definecolor{sywOrange}{rgb}{1.0,0.65,0.0}
\definecolor{sywYellow}{rgb}{1.0,0.88,0.30}
\definecolor{sywBlue}{rgb}{0.12,0.47,0.71}
\definecolor{sywGreen}{rgb}{0.13,0.53,0.23}
% Error codes (colors)
\colorlet{sywScriptDoesNotExist}{sywRed}
\colorlet{sywScriptNotVersionControlled}{sywOrange}
\colorlet{sywScriptHasUncommittedChanges}{sywYellow}
\colorlet{sywScriptUpToDate}{sywBlue}
% User-facing commands
\newcommand\GitHubSHA{((- repo.sha -))}
\newcommand\GitHubIcon{\faGithub\xspace}
\newcommand\GitHubIconRed{{\color{sywRed}\faGithub}\xspace}
\newcommand\GitHubIconOrange{{\color{sywOrange}\faGithub}\xspace}
\newcommand\GitHubIconYellow{{\color{sywYellow}\faGithub}\xspace}
\newcommand\GitHubIconBlue{{\color{sywBlue}\faGithub}\xspace}
% Key-value pairs
% See https://tex.stackexchange.com/a/48931
\def\addvalue#1#2{\expandafter\gdef\csname syw@data@\detokenize{#1}\endcsname{#2}}
\def\usevalue#1{%
\ifcsname syw@data@#1\endcsname%
\csname syw@data@#1\expandafter\endcsname%
\else%
KEYNOTFOUND%
\fi%
}
((* for key, value in labels.items() *))
\addvalue{((- key -))}{((- value -))}
((* endfor *))
% Add a GitHub link to the end of the abstract
\let\oldabstract\abstract
\let\oldendabstract\endabstract
\renewenvironment{abstract}{%
\oldabstract%
}{%
% AASTex631 hack to reduce margin separation
% in the abstract of a two-column document
%\ifcsname if@two@col\endcsname%
%\if@two@col\setlength{\marginparsep}{-45pt}\fi%
%\fi%
\marginnote{%
\href{((- repo.url -))/tree/((- repo.sha -))/}{%
\color{((- status -))}%
\faGithub%
}%
((* if CI *))
\hspace{3pt}%
\href{((- repo.url -))/actions/runs/((- run_id -))/}{%
\color{sywGreen}%
\faCheckCircle%
}%
((* endif *))
}
\oldendabstract%
}
% Hack `showkeys' to show margin links for figures
% See https://tex.stackexchange.com/a/580553
\renewcommand\showkeyslabelformat[1]{%
\IfBeginWith*{#1}{fig:}{\StrBehind*{#1}{fig:}[\syw@CurrentLabelName]%
\StrBefore*{\syw@CurrentLabelName:}{:}[\syw@CurrentLabelName]% remove label :suffix
\normalfont%
\stackon[3pt]{%
\IfEq*{\usevalue{\syw@CurrentLabelName_status}}{KEYNOTFOUND}{}{%
\raisebox{0pt}[5pt][5pt]{%
\href{((- repo.url -))/blob/((- repo.sha -))/\usevalue{\syw@CurrentLabelName_script}}{%
\color{\usevalue{\syw@CurrentLabelName_status}}\faGithub%
}%
}%
}%
}{%
\stackon[3pt]{%
\IfEq*{\usevalue{\syw@CurrentLabelName_datasetOne}}{KEYNOTFOUND}{}{%
\IfEq*{\usevalue{\syw@CurrentLabelName_datasetOne}}{UNAUTHORIZED}{%
\raisebox{0pt}[5pt][5pt]{%
\color{sywRed}\faDatabase%
}%
}{%
\raisebox{0pt}[5pt][5pt]{%
\href{\usevalue{\syw@CurrentLabelName_datasetOne}}{%
\color{sywBlue}\faDatabase%
}%
}%
}%
}%
}{%
\stackon[3pt]{%
\IfEq*{\usevalue{\syw@CurrentLabelName_datasetTwo}}{KEYNOTFOUND}{}{%
\IfEq*{\usevalue{\syw@CurrentLabelName_datasetTwo}}{UNAUTHORIZED}{%
\raisebox{0pt}[5pt][5pt]{%
\color{sywRed}\faDatabase%
}%
}{%
\raisebox{0pt}[5pt][5pt]{%
\href{\usevalue{\syw@CurrentLabelName_datasetTwo}}{%
\color{sywBlue}\faDatabase%
}%
}%
}%
}%
}{%
\IfEq*{\usevalue{\syw@CurrentLabelName_datasetThree}}{KEYNOTFOUND}{}{%
\IfEq*{\usevalue{\syw@CurrentLabelName_datasetThree}}{UNAUTHORIZED}{%
\raisebox{0pt}[5pt][5pt]{%
\color{sywRed}\faDatabase%
}%
}{%
\raisebox{0pt}[5pt][5pt]{%
\href{\usevalue{\syw@CurrentLabelName_datasetThree}}{%
\color{sywBlue}\faDatabase%
}%
}%
}%
}%
}%
}%
}%
}{}%
}
% Set the graphics path for all figures
\graphicspath{{./}{./figures/}}