Debian Codegraph @

texmf-dist/source/luatex/fits-astro/fits-astro.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2025 Valentin Dao
4 %
5 % This file may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either
7 % version 1.3 of this license or (at your option) any later
8 % version. The latest version of this license is in:
9 %
10 % http://www.latex-project.org/lppl.txt
11 %
12 % and version 1.3c or later is part of all distributions of
13 % LaTeX version 2008-05-04 or later.
14 %
15 % This work has the LPPL maintenance status 'maintained'
16 % and the current maintainer is Valentin Dao ([email protected]).
17 %
18 % This work consists of the files intexgral.ins, intexgral-fr.dtx and intexgral-en.dtx, along with the derived files intexgral.sty, intexgral-fr.pdf, and intexgral-en.pdf.
19 %
20 % The repository of this work can be found at:
21 %
22 % https://github.com/ankaa3908/intexgral
23 %
24 %<*driver>
25 % \fi
26 % \iffalse
27 \documentclass[11pt, a4paper]{l3doc}
28
29 \usepackage{fontspec}
30
31 \setmainfont{ChronicleTextG3}[
32 Extension = .otf,
33 Renderer = HarfBuzz,
34 UprightFont = *-Roman-Pro,
35 UprightFeatures = { Kerning = On },
36 ItalicFont = *-Italic-Pro,
37 BoldFont = *-Bold-Pro,
38 BoldItalicFont = *-BoldIta-Pro,
39 ]
40
41 \setsansfont{Whitney}[
42 Extension = .otf,
43 UprightFont = *-Medium,
44 ItalicFont = *-MediumItalic,
45 BoldFont = *-Bold,
46 BoldItalicFont = *-BoldItalic,
47 UprightFeatures =
48 {
49 StylisticSet = 1,
50 StylisticSet = 10,
51 StylisticSet = 11,
52 },
53 BoldFeatures =
54 {
55 StylisticSet = 1,
56 StylisticSet = 10,
57 StylisticSet = 11,
58 },
59 ItalicFeatures =
60 {
61 StylisticSet = 1,
62 StylisticSet = 10,
63 StylisticSet = 11,
64 StylisticSet = 8,
65 StylisticSet = 9
66 }
67 ]
68
69 \setmonofont{MonaspaceNeon}[
70 Extension = .otf,
71 Renderer = HarfBuzz,
72 Scale = 0.8,
73 UprightFont = *-Regular,
74 UprightFeatures = { Kerning = On },
75 ItalicFont = *-Italic,
76 BoldFont = *-Bold,
77 BoldItalicFont = *-BoldItalic,
78 ]
79
80 \usepackage{microtype}
81
82 \usepackage{fancyhdr}
83 \fancyhf{}
84 \fancyfoot[C]{\small\sffamily\itshape---\space\thepage\space\kern0.4mm\/---}
85 \renewcommand{\headrulewidth}{0pt}
86 \pagestyle{fancy}
87
88 \usepackage{fits-astro}
89
90 \usepackage[silence]{codedescribe}
91 \usepackage{hologo}
92
93 \usepackage[svgnames]{xcolor}
94
95 \definecolor{RoyalBlue}{RGB}{0, 35, 102}
96 \definecolor{RoyalRed}{RGB}{157, 16, 45}
97 \definecolor{RoyalGreen}{HTML}{48845F}
98 \definecolor{urlcolour}{HTML}{B42F5E}
99
100 \definecolor{packagecolour}{HTML}{B86B00}
101 \definecolor{keycolour}{HTML}{004766}
102 \definecolor{macrocolour}{HTML}{047658}
103 \definecolor{macrocolour2}{HTML}{630476}
104
105 \defobjectfmt{macro}{code}{color=macrocolour}
106 \defobjectfmt{pkg}{pkg}{color=packagecolour, font=\sffamily}
107
108 \newcodekey{fits}{
109 ruleht = 0,
110 texcsstyle = \bfseries\color{RoyalBlue},
111 texcs =
112 [2]{
113 loadheader,
114 showheader,
115 headerkey,
116 setheaderkey,
117 gsetheaderkey,
118 },
119 texcs =
120 [3]{
121 flameHalpha,
122 exptime,
123 observer,
124 },
125 texcsstyle = [2]{\color{macrocolour}},
126 texcsstyle = [3]{\color{macrocolour2}},
127 codeprefix = {},
128 resultprefix = {}
129 }
130
131 \lstset{
132 gobble=2,
133 }
134
135 \usepackage{titlesec}
136 \titleformat*{\section}{\sffamily\LARGE\bfseries}
137 \titleformat*{\subsection}{\sffamily\Large\bfseries}
138
139 \usepackage{changelog}
140 \usepackage{enumitem}
141 \renewenvironment{changelogitemize}
142 {\begin{itemize}[label=\raisebox{0.5ex}{$\scriptscriptstyle\blacktriangleright$}]}
143 {\end{itemize}}
144
145 \setlength{\parindent}{0pt}
146
147 \usepackage{polyglossia}
148 \setmainlanguage{english}
149
150 \usepackage[perpage]{footmisc}
151
152 \usepackage{hyperref}
153 \hypersetup{
154 pdfauthor = {Valentin Dao},
155 pdftitle = {The fits package},
156 pdfcreator = {LuaLaTeX with hyperref package},
157 colorlinks = true,
158 linkcolor = RoyalBlue,
159 urlcolor = urlcolour,
160 }
161
162 \directlua{
163 local path = '../../build.lua'
164 dofile(path)
165 local new_summary = uploadconfig.summary:gsub('LuaLaTeX', 'Lua\\TeX')
166 token.set_macro('pkgdescription', new_summary)
167 token.set_macro('pkgversion', uploadconfig.version)
168 token.set_macro('pkgname', uploadconfig.pkg)
169 token.set_macro('pkgauthor', uploadconfig.author)
170 token.set_macro('pkgemail', uploadconfig.email)
171 }
172
173 \title{The \textsf{\pkgname} package\medbreak{\Large\pkgversion}}
174 \author{\pkgauthor\footnote{E-mail: \href{mailto:[email protected]}{\ttfamily\pkgemail}}}
175 \date{\today}
176
177 \begin{document}
178 \DocInput{fits-astro.dtx}
179 \end{document}
180 %</driver>
181 % \fi
182 %
183 % \begin{documentation}
184 %
185 % \maketitle
186 %
187 % The \tsobj[pkg]{\pkgname} package provides a simple interface to read Flexible Image Transport System (FITS) files and access their header to retrieve information. It relies on a custom Lua script and therefore requires the Lua\hologo{LaTeXTeX} engine. Unlike more complex libraries, such as \texttt{astropy.io.fits} in Python, this package is designed solely for directly recovering key-value pairs from headers. It is \emph{not} intended for modifying the header or fixing standardisation issues, let alone for reading the data part.
188 %
189 % \section{Loading the package}
190 %
191 % The package may be loaded in either of the following ways:
192 % \begin{itemize}
193 % \item \tsobj[code]{\usepackage{fits-astro}} if compiling with Lua\LaTeX.
194 % \item \tsobj[code]{\input{fits-astro.tex}} if compiling with Lua\TeX.
195 % \end{itemize}
196 %
197 % \section{Package macros}
198 %
199 % \begin{codedescribe}[macro]{\loadheader}
200 % \begin{codesyntax}
201 % \tsobj[code]{\loadheader}\tsargs[marg]{FITS identification}\tsargs[marg]{FITS file path}
202 % \end{codesyntax}
203 % This macro reads the \texttt{FITS} file and allocates the header information to the specified FITS identification, which can either be a string or a control sequence (similarly to how \tsobj[macro]{\newread} works for file streams). In the latter case, \tsobj[macro]{\csstring} is used to convert the control sequence to a string for internal storage. Therefore, if a control sequence is specified, it does not actually contain the header in any way. As a result, the two inputs are interchangeable. The macro furthermore uses the \texttt{Kpathsea} library, so the file shouldn't necessarily be in the current directory.
204 % \end{codedescribe}
205 %
206 % \begin{codestore}[loadfits]
207 % \loadheader\flameHalpha{Halpha_raw.fits} % A frame of the Flame Nebula with H-alpha filter
208 % \loadheader{flameHalpha}{Halpha_raw.fits} % Alternative way to load the file
209 % \end{codestore}
210 %
211 % \tscode*[fits]{loadfits}
212 % \loadheader\flameHalpha{Halpha_raw.fits}
213 %
214 % \begin{codedescribe}[macro]{\showheader}
215 % \begin{codesyntax}
216 % \tsobj[code]{\showheader}\tsargs[marg]{FITS identification}
217 % \end{codesyntax}
218 % This macro displays the header information for the specified FITS identification in the log file.
219 % \end{codedescribe}
220 %
221 % \begin{codestore}[showfits]
222 % \showheader\flameHalpha
223 % \showheader{flameHalpha} % Would produce the same result
224 % \end{codestore}
225 %
226 % \tscode*[fits]{showfits}
227 %
228 % \begin{codedescribe}[macro]{\headerkey}
229 % \begin{codesyntax}
230 % \tsobj[code]{\headerkey}\tsargs[marg]{FITS identification}\tsargs[marg]{key}
231 % \end{codesyntax}
232 % This macro retrieves the value associated with the specified key from the header of the given FITS identification.
233 % \end{codedescribe}
234 %
235 % \begin{codestore}[keyfits]
236 % \headerkey\flameHalpha{OBJECT}\par
237 % \headerkey\flameHalpha{FILTER}
238 % \end{codestore}
239 %
240 % \tsdemo[fits]{keyfits}
241 %
242 % \begin{codedescribe}[macro]{\setheaderkey, \gsetheaderkey}
243 % \begin{codesyntax}
244 % \tsobj[code]{\setheaderkey}\tsargs[marg]{FITS identification}\tsargs[marg]{key}\tsargs[marg]{control sequence}
245 % \end{codesyntax}
246 % This macro retrieves the value associated with the specified key from the header of the given FITS identification and assigns it to the specified control sequence. The assignment is either local to the current group or global.
247 % \end{codedescribe}
248 %
249 % \begin{codestore}[setfitskey]
250 % \tt
251 % \begingroup
252 % \setheaderkey\flameHalpha{EXPTIME}\exptime
253 % \gsetheaderkey\flameHalpha{OBSERVER}\observer
254 % \meaning\exptime\par
255 % \endgroup
256 % \meaning\exptime\par
257 % \meaning\observer
258 % \end{codestore}
259 %
260 % \tsdemo[fits]{setfitskey}
261 %
262 % \begin{changelog}[sectioncmd=\section*]
263 % \shortversion{v=1.0.0, date=06-04-2026, changes=Initial version.}
264 % \end{changelog}
265 %
266 % \end{documentation}
267 %
268 % \newpage
269 %
270 % \section{Implementation}
271 %
272 % \subsection{\TeX\ package}
273 %
274 % \begin{implementation}
275 %
276 % \begin{macrocode}
277 %<*package-tex>
278 \ifdefined\loadheader\expandafter\endinput\fi
279
280 \def\FITSerr#1{\errmessage{Package fits Error: #1}}
281 \def\FITSwar#1{\message{Package fits Warning: #1}}
282
283 \unless\ifdefined\directlua
284 \FITSerr{LuaTeX required}
285 \fi
286
287 \directlua{dofile('fits-astro.lua')}
288
289 \def\loadheader#1#2{
290 \directlua{
291 local key = '\csstring#1'
292 if FITS_data[key] then
293 tex.print('\luaescapestring{\FITSerr{FITS file '#2' already loaded}}')
294 else
295 FITS_data[key] = load_fits('#2')
296 end
297 }
298 }
299
300 \def\showheader#1{
301 \directlua{
302 show_fits(FITS_data['\csstring#1'])
303 }
304 }
305
306 \def\headerkey#1#2{
307 \directlua{
308 if FITS_data['\csstring#1']['#2'] then
309 get_header_key(FITS_data['\csstring#1'], '#2')
310 else
311 tex.print('\luaescapestring{\FITSwar{Header key '#2' not found}}')
312 end
313 }
314 }
315
316 \def\setheaderkey#1#2#3{
317 \directlua{
318 if FITS_data['\csstring#1']['#2'] then
319 token.set_macro('\csstring#3', FITS_data['\csstring#1']['#2'])
320 end
321 }
322 }
323
324 \def\gsetheaderkey#1#2#3{
325 \directlua{
326 if FITS_data['\csstring#1']['#2'] then
327 token.set_macro('\csstring#3', FITS_data['\csstring#1']['#2'], 'global')
328 end
329 }
330 }
331 %</package-tex>
332 % \end{macrocode}
333 % \subsection{\LaTeX\ package}
334 % \makeatletter
335 % \c@CodelineNo=\z@
336 % \makeatother
337 % \begin{macrocode}
338 %<*package-latex>
339 \NeedsTeXFormat{LaTeX2e}
340 \ProvidesPackage{fits-astro}[2026-04-06 v1.0.0 Retrieving FITS file header information in LuaTeX]
341
342 \input{fits-astro.tex}
343 %</package-latex>
344 % \end{macrocode}
345 % \end{implementation}