-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (124 loc) · 5.09 KB
/
build_preprint.yml
File metadata and controls
149 lines (124 loc) · 5.09 KB
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
name: Build Professional Preprint
on:
push:
branches: [main]
env:
# Opting into Node.js 24 as per GitHub's 2025 deprecation roadmap
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
build-paper:
runs-on: ubuntu-latest
name: Build Preprint PDF
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y pandoc texlive texlive-latex-extra texlive-fonts-recommended texlive-xetex texlive-fonts-extra zip python3-yaml
- name: Extract Metadata and Build LaTeX Title
run: |
python3 - << 'PYEOF'
import yaml
import os
# Ensure we are reading the correct path
file_path = 'paper/paper.md'
if not os.path.exists(file_path):
file_path = 'paper.md'
with open(file_path, 'r') as f:
content = f.read()
parts = content.split('---\n')
fm = yaml.safe_load(parts[1])
authors = fm.get('authors', [])
affiliations = fm.get('affiliations', [])
aff_map = {str(a['index']): a for a in affiliations}
# 1. Generate Pandoc Metadata
meta = {
'title': fm.get('title', ''),
'date': str(fm.get('date', '')),
'colorlinks': True,
'linkcolor': 'blue',
'urlcolor': 'blue',
'citecolor': 'blue',
'geometry': 'a4paper, margin=2.5cm',
}
with open('/tmp/pandoc_meta.yaml', 'w') as f:
yaml.dump(meta, f)
# 2. Build LaTeX Title Block
lines = [r'\begin{center}']
lines.append(r'{\LARGE\bfseries ' + fm.get('title','').replace('&', r'\&') + r'}\\[1.2em]')
auth_line = []
for a in authors:
name = a['name'].replace('&', r'\&')
aff_indices = str(a.get('affiliation', '')).split(',')
marker = ",".join([idx.strip() for idx in aff_indices])
if a.get('corresponding'):
marker += r",*"
auth_line.append(rf'{name}$^{{{marker}}}$')
lines.append(r'\large ' + r', '.join(auth_line) + r'\\[0.8em]')
for idx, aff in sorted(aff_map.items()):
name = aff['name'].replace('&', r'\&')
ror_id = aff.get('ror', '')
ror_link = rf" \small (ROR: \href{{https://ror.org/{ror_id}}}{{{ror_id}}})" if ror_id else ""
lines.append(rf'$^{{{idx}}}$\small {name}{ror_link}\\[0.2em]')
corres = [a for a in authors if a.get('corresponding') and a.get('email')]
if corres:
email = corres[0]['email']
lines.append(rf'\small $^*$Corresponding author: \href{{mailto:{email}}}{{{email}}}\\[0.2em]')
lines.append(r'\small DOI: \href{https://doi.org/10.5281/zenodo.18377216}{10.5281/zenodo.18377216}\\[0.2em]')
lines.append(r'\small ' + str(fm.get('date','')))
lines.append(r'\end{center}')
lines.append(r'\vspace{0.5em}\noindent\rule{\textwidth}{0.6pt}\vspace{1.5em}')
with open('/tmp/title_block.tex', 'w') as f:
f.write('\n'.join(lines))
PYEOF
- name: Create Professional Header
run: |
cat > /tmp/header.tex << 'EOF'
\usepackage{hyperref}
\usepackage{xurl}
\usepackage{fontspec}
\setmainfont{TeX Gyre Termes}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Termes Math}
\usepackage{fancyhdr}
\usepackage{xcolor}
\hypersetup{
breaklinks=true,
colorlinks=true,
linkcolor=blue,
urlcolor=blue,
citecolor=blue,
pdfauthor={Deshmukh and Mukherjee},
pdftitle={PICA: High-Precision Automation}
}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\small \textbf{\textcolor{gray}{PREPRINT -- NOT PEER REVIEWED}}}
\fancyhead[R]{\small \textit{PICA: Python-based Instrument Control and Automation}}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\maketitle}{}
EOF
- name: Generate Publication-Ready PDF
run: |
TARGET_DIR="paper"
if [ ! -d "$TARGET_DIR" ]; then TARGET_DIR="."; fi
cd $TARGET_DIR
awk '/^# AI usage disclosure/{skip=1} /^# / && !/^# AI usage disclosure/{skip=0} !skip' paper.md > paper_cleaned.md
pandoc paper_cleaned.md -o paper.pdf \
--standalone \
--citeproc \
--pdf-engine=xelatex \
--metadata-file=/tmp/pandoc_meta.yaml \
--include-in-header=/tmp/header.tex \
--include-before-body=/tmp/title_block.tex \
--variable=link-citations=true
rm paper_cleaned.md
- name: Upload Artifact
uses: actions/upload-artifact@v6
with:
name: professional-preprint
path: |
paper/paper.pdf
paper.pdf