-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatex.py
executable file
·95 lines (71 loc) · 2.39 KB
/
latex.py
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
# Print a LaTeX source file of the glossary from the xlsx file
import glossaryformatter as gf
import sys
# check that we have a single argument i.e. the filename
if len(sys.argv) == 1:
raise RuntimeError('Please supply the name of the glossary xlsx file')
elif len(sys.argv) > 2:
raise RuntimeError('Please supply the name of the glossary xlsx file as ' +
'single argument')
gf.set_output_encoding()
# list of headers for reference columns
ref_cols = ['Piece 1', 'Piece 2']
# beginning of LaTeX file
print(r"""\documentclass[10pt,a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{charter}
\usepackage{microtype}
\usepackage{multicol}
\usepackage{titlesec}
\usepackage{enumitem}
\setlength\parindent{0pt}
\setlength\parskip{6pt plus 2pt minus 1pt}
\setlength\columnsep{1cm}
\setlist[itemize]{leftmargin=*}
\providecommand\tightlist{
\setlength{\itemsep}{6pt plus 3pt minus 3pt}
\setlength{\parskip}{0pt}}
\titlespacing\section{0pt}{12pt}{0pt}
\titlespacing\subsection{0pt}{6pt}{3pt}
\titlespacing\subsubsection{0pt}{6pt}{3pt}
\setcounter{secnumdepth}{0}
\newcommand\term[1]{\item \textbf{#1}}
\newcommand\definition[1]{ -- #1}
\newcommand\refs[1]{\textsuperscript{ (#1)}}
\newcommand\separator{\vspace{6pt}\hrule}
\begin{document}
\section{Glossary}
""")
# reference legend
n = 1
for this_piece in ref_cols:
print(r'\textsuperscript{' + str(n) + '} ' + this_piece)
if n != len(ref_cols):
print(r'\\[3pt]')
n += 1
print(r"""
\vspace{9pt}
\separator
\begin{multicols}{2}
""")
# the main chunk of the glossary
the_terms = gf.get_terms_excel(filename=sys.argv[1], last_col=6)
gf.print_glossary(the_terms,
subcat_col = 'Sub-category',
cat_prefix = '\subsection{',
cat_suffix = '}\n',
subcat_prefix = '\subsubsection{',
subcat_suffix = '}\n',
begin_terms = '\\begin{itemize}\n\\tightlist\n',
end_terms = '\n\end{itemize}\n\n\\separator\n',
term_prefix = '\\term{',
term_suffix = '}',
def_prefix = '\definition{',
def_suffix = '}',
ref_cols = ref_cols,
refs_prefix = '\\refs{',
refs_separator = ',',
refs_suffix = '}')
# end of LaTeX file
print(r"""\end{multicols}
\end{document}""")