Skip to content

Commit 4a35e20

Browse files
committed
feat: XCPC-template: pdf export
1 parent fa6334e commit 4a35e20

21 files changed

Lines changed: 1164 additions & 671 deletions

File tree

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release PDF
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v5
17+
- uses: actions/setup-python@v6
18+
with:
19+
python-version: '3.x'
20+
# cache not work because restriction between different tags
21+
# cache: 'pip'
22+
- run: |
23+
pip install -r requirements.txt
24+
python main.py --output-file output.tex
25+
python main.py --config-file config-compact.yml --output-file output-compact.tex
26+
- run: |
27+
chmod +x script.sh
28+
./script.sh
29+
- uses: xu-cheng/latex-action@v4
30+
with:
31+
root_file: |
32+
output.tex
33+
output-compact.tex
34+
latexmk_use_xelatex: true
35+
extra_fonts: |
36+
./fonts/*.otf
37+
./fonts/*.ttf
38+
- name: Rename Output Files
39+
run: |
40+
for f in output*.pdf; do
41+
if [ ! -e "$f" ]; then
42+
continue
43+
fi
44+
base="${f%.*}"
45+
ext=".${f##*.}"
46+
mv -- "$f" "${base}_${{ github.ref_name }}${ext}"
47+
done
48+
- name: Release
49+
uses: softprops/action-gh-release@v2
50+
with:
51+
files: "*_${{ github.ref_name }}.pdf"

LICENSE

Lines changed: 18 additions & 671 deletions
Large diffs are not rendered by default.

config-compact.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root-directory: src/alfred
2+
latex-pre: latex-compact-pre.tex
3+
latex-post: latex-post.tex
4+
title: Alfred's ICPC Templates
5+
author: Alfred Chester

config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root-directory: src/alfred
2+
latex-pre: latex-pre.tex
3+
latex-post: latex-post.tex
4+
title: Alfred's ICPC Templates
5+
author: Alfred Chester

gen.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/opt/homebrew/bin/bash
2+
3+
# Initialize recursive option to false
4+
RECURSIVE=false
5+
6+
# Check if the first argument is the -r option
7+
if [ "$1" == "-r" ]; then
8+
RECURSIVE=true
9+
shift # Skip the first argument -r, subsequent arguments are all directories
10+
fi
11+
12+
# Create a function to process a single directory
13+
process_directory() {
14+
local current_dir="$1"
15+
local output_file="$current_dir/config.yml"
16+
17+
# Clear or create the config.yml file
18+
echo "contents:" | iconv -t UTF-8 > "$output_file"
19+
20+
# Create an associative array to track processed files
21+
declare -A processed_files
22+
23+
# Iterate through the current directory and files
24+
for entry in "$current_dir"/*; do
25+
if [ -d "$entry" ]; then
26+
# Process subdirectories
27+
dir_name=$(basename "$entry")
28+
echo " - name: $dir_name" | iconv -t UTF-8 >> "$output_file"
29+
echo " directory: $dir_name" | iconv -t UTF-8 >> "$output_file"
30+
31+
# If recursive is enabled, recursively call the function for subdirectories
32+
if [ "$RECURSIVE" = true ]; then
33+
process_directory "$entry"
34+
fi
35+
elif [ -f "$entry" ]; then
36+
# Get the filename
37+
filename=$(basename "$entry")
38+
39+
# Skip the config.yml file in the current directory
40+
if [ "$filename" == "config.yml" ]; then
41+
continue
42+
fi
43+
44+
# Check the file type and get the base name
45+
if [[ "$filename" == *.hpp ]]; then
46+
base_name="${filename%.hpp}"
47+
elif [[ "$filename" == *.py ]]; then
48+
base_name="${filename%.py}"
49+
elif [[ "$filename" == *.h ]]; then
50+
base_name="${filename%.h}"
51+
elif [[ "$filename" == *.json ]]; then
52+
base_name="${filename%.json}"
53+
elif [[ "$filename" == *-pre.tex ]]; then
54+
base_name="${filename%-pre.tex}"
55+
elif [[ "$filename" == *-post.tex ]]; then
56+
base_name="${filename%-post.tex}"
57+
else
58+
echo "Unrecognized file: $filename"
59+
continue # Skip other unrelated files
60+
fi
61+
62+
# If this file has not been processed before
63+
if [ -z "${processed_files[$base_name]}" ]; then
64+
processed_files[$base_name]=1 # Mark as processed
65+
66+
# Prepare to start generating entries
67+
echo " - name: $base_name" | iconv -t UTF-8 >> "$output_file"
68+
69+
# Collect possible codes into an array
70+
echo " codes:" | iconv -t UTF-8 >> "$output_file"
71+
72+
if [ -f "$current_dir/$base_name.hpp" ]; then
73+
echo " - $base_name.hpp" | iconv -t UTF-8 >> "$output_file"
74+
fi
75+
if [ -f "$current_dir/$base_name.h" ]; then
76+
echo " - $base_name.h" | iconv -t UTF-8 >> "$output_file"
77+
fi
78+
if [ -f "$current_dir/$base_name.json" ]; then
79+
echo " - $base_name.json" | iconv -t UTF-8 >> "$output_file"
80+
fi
81+
if [ -f "$current_dir/$base_name.py" ]; then
82+
echo " - $base_name.py" | iconv -t UTF-8 >> "$output_file"
83+
fi
84+
85+
# Process pre-code and post-code files
86+
if [ -f "$current_dir/$base_name-pre.tex" ]; then
87+
echo " code-pre: $base_name-pre.tex" | iconv -t UTF-8 >> "$output_file"
88+
fi
89+
if [ -f "$current_dir/$base_name-post.tex" ]; then
90+
echo " code-post: $base_name-post.tex" | iconv -t UTF-8 >> "$output_file"
91+
fi
92+
fi
93+
fi
94+
done
95+
96+
echo "Generated config.yml file at: $output_file"
97+
}
98+
99+
for dir in "$@"; do
100+
if [ -d "$dir" ]; then
101+
process_directory "$dir"
102+
else
103+
echo "Warning: $dir is not a valid directory, skipping processing."
104+
fi
105+
done

latex-compact-pre.tex

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
\documentclass{article}
2+
\usepackage[fontset=none]{ctex}
3+
\usepackage{amsmath, amsthm, amssymb}
4+
\usepackage{lmodern}
5+
\usepackage{listings,xcolor}
6+
\usepackage{geometry}
7+
\usepackage{fontspec}
8+
\usepackage{graphicx}
9+
\usepackage[colorlinks, linkcolor=blue, anchorcolor=blue, citecolor=green]{hyperref}
10+
\usepackage{setspace}
11+
\usepackage{fancyhdr}
12+
\usepackage{titletoc}
13+
14+
% 页面布局紧凑设置
15+
\geometry{a4paper, left=1.5cm, right=1.5cm, top=2cm, bottom=2cm} % 减小边距
16+
\setlength{\footskip}{20pt} % 减小页脚间距
17+
18+
% 字体设置
19+
\setCJKmainfont{Source Han Sans HW SC}[
20+
ItalicFont={Source Han Sans HW SC},
21+
ItalicFeatures={FakeSlant=0.2}
22+
]
23+
\setCJKsansfont{Source Han Sans HW SC}[
24+
ItalicFont={Source Han Sans HW SC},
25+
ItalicFeatures={FakeSlant=0.2}
26+
]
27+
\setCJKmonofont{Source Han Sans HW SC}[
28+
ItalicFont={Source Han Sans HW SC},
29+
ItalicFeatures={FakeSlant=0.2}
30+
]
31+
32+
\setmainfont{Inconsolata LGC Nerd Font Mono}
33+
\setsansfont{Inconsolata LGC Nerd Font Mono}
34+
\setmonofont{Inconsolata LGC Nerd Font Mono}
35+
36+
% 取消首行缩进和减小行间距
37+
\setlength{\parindent}{0pt} % 无首行缩进
38+
\setstretch{1.0} % 行距调整为 1.0
39+
40+
% 页眉页脚紧凑设置
41+
\setlength{\headheight}{13pt}
42+
\pagestyle{fancy}
43+
\fancyhf{}
44+
\fancyhead[L]{\leftmark} % 页眉左侧显示章节名
45+
\fancyfoot[C]{\thepage} % 页脚中间显示页码
46+
47+
% 代码样式设置
48+
\lstdefinestyle{cppstyle}{
49+
language=C++, % 语言设置为 C++
50+
basicstyle=\ttfamily\small\linespread{1.0}\selectfont,
51+
keywordstyle=\color{blue}\bfseries, % 关键字颜色
52+
commentstyle=\color{gray}\itshape, % 注释颜色,斜体
53+
stringstyle=\color{red}, % 字符串颜色
54+
numbers=left, % 行号显示在左侧
55+
numberstyle=\small\color{gray}, % 行号样式
56+
stepnumber=1, % 行号递增
57+
numbersep=10pt, % 行号和代码的间隔
58+
backgroundcolor=\color{gray!5},
59+
showspaces=false, % 不显示空格
60+
showstringspaces=false, % 字符串中不显示空格
61+
breaklines=true, % 自动换行
62+
frame=single, % 给代码添加边框
63+
rulecolor=\color{black!30}, % 边框颜色
64+
tabsize=4, % 设置 Tab 宽度
65+
captionpos=b % 标题位置
66+
}
67+
68+
\lstdefinestyle{pythonstyle}{
69+
language=Python, % 语言设置为 Python
70+
basicstyle=\ttfamily\small\linespread{1.0}\selectfont,
71+
keywordstyle=\color{blue}\bfseries, % 关键字颜色
72+
commentstyle=\color{gray}\itshape, % 注释颜色,斜体
73+
stringstyle=\color{red}, % 字符串颜色
74+
numbers=left, % 行号显示在左侧
75+
numberstyle=\small\color{gray}, % 行号样式
76+
stepnumber=1, % 行号递增
77+
numbersep=10pt, % 行号和代码的间隔
78+
backgroundcolor=\color{gray!5},
79+
showspaces=false, % 不显示空格
80+
showstringspaces=false, % 字符串中不显示空格
81+
breaklines=true, % 自动换行
82+
frame=single, % 给代码添加边框
83+
rulecolor=\color{black!30}, % 边框颜色
84+
tabsize=4, % 设置 Tab 宽度
85+
captionpos=b % 标题位置
86+
}
87+
88+
\lstdefinestyle{javastyle}{
89+
language=Java, % 语言设置为 Java
90+
basicstyle=\ttfamily\small\linespread{1.0}\selectfont,
91+
keywordstyle=\color{blue}\bfseries, % 关键字颜色
92+
commentstyle=\color{gray}\itshape, % 注释颜色,斜体
93+
stringstyle=\color{red}, % 字符串颜色
94+
numbers=left, % 行号显示在左侧
95+
numberstyle=\small\color{gray}, % 行号样式
96+
stepnumber=1, % 行号递增
97+
numbersep=10pt, % 行号和代码的间隔
98+
backgroundcolor=\color{gray!5},
99+
showspaces=false, % 不显示空格
100+
showstringspaces=false, % 字符串中不显示空格
101+
breaklines=true, % 自动换行
102+
frame=single, % 给代码添加边框
103+
rulecolor=\color{black!30}, % 边框颜色
104+
tabsize=4, % 设置 Tab 宽度
105+
captionpos=b % 标题位置
106+
}
107+
108+
109+
% 标题样式设置
110+
\usepackage{titlesec}
111+
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}
112+
\titleformat{\subsection}{\normalsize\bfseries}{\thesubsection}{1em}{}
113+
\titleformat{\subsubsection}{\small\bfseries}{\thesubsubsection}{1em}{}
114+
115+
% 目录样式设置
116+
\usepackage{tocloft}
117+
\cftsetindents{subsection}{1.2em}{2.5em}
118+
\cftsetindents{subsubsection}{2.5em}{3.5em}
119+
120+
% 封面设置
121+
\title{{PLACEHOLDER:TITLE}}
122+
\author{{PLACEHOLDER:AUTHOR}}
123+
\date{\today}
124+
125+
\begin{document}
126+
127+
% 封面内容
128+
\maketitle
129+
{
130+
\hypersetup{linkcolor=black}
131+
\tableofcontents
132+
}
133+
134+
\newpage

latex-post.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\end{document}

0 commit comments

Comments
 (0)