-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathox-gost.el
320 lines (292 loc) · 12.9 KB
/
ox-gost.el
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
(require 'org-macs)
(require 'cl-lib)
(require 'ox)
(require 'ox-publish)
(require 'ox-latex)
(require 'engrave-faces)
;; Создаём потомка экспорта ox-latex
(org-export-define-derived-backend 'gost 'latex
;; Объявляем меню
:menu-entry '(?g "Export to GOST 7.32" org-gost-export-to-pdf)
:filters-alist '((:filter-table . gost-filter-table))
:options-alist '(
(:latex-classes nil nil org-gost-classes)
(:latex-toc-command nil nil org-gost-toc-command)
(:latex-title-command nil nil org-gost-title-command)
(:latex-class nil nil "extarticle")
(:latex-minted-options nil nil org-gost-minted-options)
(:latex-default-table-environment nil nil org-gost-default-table-environment)
(:latex-header nil nil org-gost-latex-headers newline)
(:latex-src-block-backend nil nil org-gost-src-block-backend)
;; Мои собственные параметры
(:teacher "TEACHER" nil org-gost-teacher newline)
(:teacher-position "POSITION" nil org-gost-teacher-position newline)
(:education-organization "EDUORG" nil org-gost-education-organization parse)
(:type-of-work "TYPE" nil org-gost-type-work parse)
(:course "COURSE" nil org-gost-course-name parse)
(:department "DEPARTMENT" nil org-gost-department parse)
(:city "CITY" nil org-gost-city parse)
(:group-name "GROUP" nil org-gost-group)
)
:translate-alist '((template . org-gost-template))
)
(defcustom org-gost-education-organization "Образовательная организация"
"Укзывается название организациии для титульного листа"
:group 'org-gost
:type 'string)
(defcustom org-gost-teacher ""
"Преподаватели для титульного листа"
:group 'org-gost
:type 'string)
(defcustom org-gost-type-work "ОТЧЕТ О ЛАБОРАТОРНОЙ РАБОТЕ"
"Тип работы для титульного лица"
:group 'org-gost
:type 'string)
(defcustom org-gost-department "Факультет или департамент"
"Факультет для титульного лица"
:group 'org-gost
:type 'string)
(defcustom org-gost-teacher-position "преподаватель"
"Факультет для титульного лица"
:group 'org-gost
:type 'string)
(defcustom org-gost-city "Город"
"Город для титульного листа"
:group 'org-gost
:type 'string)
(defcustom org-gost-course-name ""
"Название курса"
:group 'org-gost
:type 'string)
(defcustom org-gost-group "000"
"Наименование группы для титульного листа"
:group 'org-gost
:type 'string)
(defun org-gost--format-spec (info)
"Create a format-spec for document meta-data.
INFO is a plist used as a communication channel."
(let ((language (let* ((lang (plist-get info :language))
(plist (cdr
(assoc lang org-latex-language-alist))))
;; Here the actual name of the LANGUAGE or LANG is used.
(or (plist-get plist :lang-name)
lang))))
`((?a . ,(org-export-data (plist-get info :author) info))
(?t . ,(org-export-data (plist-get info :title) info))
(?s . ,(org-export-data (plist-get info :subtitle) info))
(?k . ,(org-export-data (org-latex--wrap-latex-math-block
(plist-get info :keywords) info)
info))
(?d . ,(org-export-data (plist-get info :teacher) info))
(?e . ,(org-export-data (plist-get info :education-organization) info))
(?T . ,(org-export-data (plist-get info :type-of-work) info))
(?u . ,(org-export-data (plist-get info :course) info))
(?f . ,(org-export-data (plist-get info :department) info))
(?p . ,(org-export-data (plist-get info :teacher-position) info))
(?C . ,(org-export-data (plist-get info :city) info))
(?g . ,(org-export-data (plist-get info :group-name) info))
(?c . ,(plist-get info :creator))
(?l . ,language)
(?L . ,(capitalize language))
(?D . ,(org-export-data (org-export-get-date info) info)))))
(defun org-gost-template (contents info)
"Return complete document string after LaTeX conversion.
CONTENTS is the transcoded contents string. INFO is a plist
holding export options."
(let ((title (org-export-data (plist-get info :title) info))
(spec (org-gost--format-spec info)))
(concat
;; Time-stamp.
(and (plist-get info :time-stamp-file)
(format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
;; LaTeX compiler.
(org-latex--insert-compiler info)
;; Document class and packages.
(org-latex-make-preamble info)
;; Possibly limit depth for headline numbering.
(let ((sec-num (plist-get info :section-numbers)))
(when (integerp sec-num)
(format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
;; Author.
(let ((author (and (plist-get info :with-author)
(let ((auth (plist-get info :author)))
(and auth (org-export-data auth info)))))
(email (and (plist-get info :with-email)
(org-export-data (plist-get info :email) info))))
(cond ((and author email (not (string= "" email)))
(format "\\author{%s\\thanks{%s}}\n" author email))
((or author email) (format "\\author{%s}\n" (or author email)))))
;; Date.
;; LaTeX displays today's date by default. One can override this by
;; inserting \date{} for no date, or \date{string} with any other
;; string to be displayed as the date.
(let ((date (and (plist-get info :with-date) (org-export-get-date info))))
(format "\\date{%s}\n" (org-export-data date info)))
;; Title and subtitle.
(let* ((subtitle (plist-get info :subtitle))
(formatted-subtitle
(when subtitle
(format (plist-get info :latex-subtitle-format)
(org-export-data subtitle info))))
(separate (plist-get info :latex-subtitle-separate)))
(concat
(format "\\title{%s%s}\n" title
(if separate "" (or formatted-subtitle "")))
(when (and separate subtitle)
(concat formatted-subtitle "\n"))))
;; Hyperref options.
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
;; engrave-faces-latex preamble
(when (eq org-gost-src-block-backend 'engraved) ;; Исправить на использование из get info значения
(org-latex-generate-engraved-preamble info))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
(let* ((title-command (plist-get info :latex-title-command))
(command (and (stringp title-command)
(format-spec title-command spec))))
(org-element-normalize-string
(cond ((not (plist-get info :with-title)) nil)
((string= "" title) nil)
((not (stringp command)) nil)
((string-match "\\(?:[^%]\\|^\\)%s" command)
(format command title))
(t command))))
;; Table of contents.
(let ((depth (plist-get info :with-toc)))
(when depth
(concat (when (integerp depth)
(format "\\setcounter{tocdepth}{%d}\n" depth))
(plist-get info :latex-toc-command))))
;; Document's body.
contents
;; Creator.
(and (plist-get info :with-creator)
(concat (plist-get info :creator) "\n"))
;; Document end.
"\\end{document}")))
(defun gost-filter-table (text backend info)
"Функция исправления таблички"
(replace-regexp-in-string "Continued on next page" "Продолжение на следующей странице" (replace-regexp-in-string "Continued from previous page" "Продолжение с предыдущей страницы" text)))
;; Просто экспортируем файл в pdf
(defun org-gost-export-to-pdf
(&optional async subtreep visible-only body-only ext-plist)
"Export current buffer to GOST 7.32 file"
(interactive)
(let ((outfile (org-export-output-file-name ".tex" subtreep)))
(org-export-to-file 'gost outfile
async subtreep visible-only body-only ext-plist
#'org-latex-compile)))
(setq org-gost-classes
'(("extarticle" "\\documentclass[14pt]{extarticle}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
("article" "\\documentclass[11pt]{article}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
("report" "\\documentclass[11pt]{report}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
("book" "\\documentclass[11pt]{book}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
(setq org-gost-title-command (concat
"\\begin{small}\n\\begin{titlepage}\n\n"
"\\linespread{1}\\selectfont"
"\\centering{%e}\n\n"
"\\vspace{32pt}\n\n"
"\\centering{%f}\n\n"
"\\vspace{60pt}\n\n"
"\\raggedright{ОТЧЕТ \\\\
ЗАЩИЩЕН С ОЦЕНКОЙ}\n"
"\\vspace{14pt}\n\n"
"\\raggedright{ПРЕПОДАВАТЕЛЬ}\n\n"
"\\vspace{12pt}\n\n"
"\\begin{tabularx}{\\textwidth}{ >{\\centering\\arraybackslash}X >{\\centering\\arraybackslash}X >{\\centering\\arraybackslash}X }\n"
"\t %p & & %d \\\\ \n"
"\t \\hrulefill & \\hrulefill & \\hrulefill \\\\ \n"
"\\footnotesize{должность, уч. степень, звание} & \\footnotesize{подпись, дата} & \\footnotesize{инициалы, фамилия} \\\\ \n"
"\\end{tabularx} \n \n"
"\\vspace{48pt} \n\n"
"\\centering{%T} \n\n"
"\\vspace{40pt} \n\n"
"\\centering{%t} \n\n"
"\\vspace{40pt} \n\n"
"\\centering{По курсу: %u} \n\n"
"\\vspace*{\\fill} \n\n"
"\\raggedright{РАБОТУ ВЫПОЛНИЛ} \n\n"
"\\vspace{10pt} \n\n"
"\\begin{tabularx}{\\textwidth}{>{\\raggedright\\arraybackslash}X >{\\centering\\arraybackslash}X >{\\centering\\arraybackslash}X >{\\centering\\arraybackslash}X }\n"
"СТУДЕНТ ГР. № & %g & & %a \\\\ \n"
"\t & \\hrulefill & \\hrulefill & \\hrulefill \\\\ \n"
"\t & & \\footnotesize{подпись, дата} & \\footnotesize{инициалы, фамилия} \\\\ \n"
"\\end{tabularx} \n \n"
"\\vspace*{\\fill} \n\n"
"\\centering{%C \\the\\year} \n\n"
"\\end{titlepage}\n\\end{small}\n"
))
(setq org-gost-toc-command "\n\\tableofcontents \\clearpage\n")
;; Надо как-то исправить
(setq org-gost-latex-headers
"\\usepackage[russian]{babel}
\\usepackage{tempora}
\\usepackage{geometry}
\\geometry{a4paper, left=30mm, top=20mm, bottom=20mm, right=15mm }
\\usepackage{graphicx}
\\usepackage{array}
\\usepackage{tabularx}
\\usepackage{listings}
\\usepackage{float}
\\usepackage{setspace}
\\usepackage{tabularx}
\\usepackage{longtable}
\\usepackage{titlesec}
\\titleformat{\\section}{\\normalsize\\bfseries}{}{1.25cm}{}
\\titleformat{\\subsection}{\\normalsize\\bfseries}{}{1.25cm}{}
\\titleformat{\\subsubsection}{\\normalsize\\bfseries}{}{1.25cm}{}
\\addto\\captionsrussian{\\renewcommand{\\contentsname}{\\centering \\normalsize СОДЕРЖАНИЕ}}
\\addtocontents{toc}{\\protect\\thispagestyle{empty}}
\\usepackage{titletoc}
\\titlecontents{section}[0pt]{}{\\contentsmargin{0pt} \\thecontentslabel\\enspace}{\\contentsmargin{0pt}}{\\titlerule*[0.5pc]{.}\\contentspage}[]
\\dottedcontents{subsection}[3.1em]{}{1.5em}{0.5pc}
\\usepackage{caption}
\\DeclareCaptionLabelSeparator{custom}{ -- }
\\captionsetup[figure]{name=Рисунок, labelsep=custom, font={onehalfspacing}, justification=centering}
\\usepackage{ragged2e}
\\justifying
\\setlength\\parindent{1.25cm}
\\sloppy
\\usepackage{indentfirst}
\\usepackage{multirow}
\\usepackage{lscape}
\\renewcommand{\\labelitemi}{\\textsc{--}}
\\linespread{1.3}
% Настройка caption для стиля
\\DeclareCaptionStyle{leftalign}{justification=raggedright}
\\captionsetup[listing]{style=leftalign, labelsep=custom, name=Листинг} % Правим позицию заголовка для listing
\\usepackage{enumitem}
\\setlist[enumerate]{itemindent=1.85cm,leftmargin=0pt}
" )
(setq
org-gost-minted-options '(("breaklines" "true")
("float" "t")
("breakanywhere" "true")
("fontsize" "\\footnotesize"))
org-gost-default-table-environment "longtable"
org-gost-src-block-backend 'engraved)
;;;###autoload
(provide 'ox-gost)