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
|
;;; dinbrief.el --- Special code for LaTeX-Style dinbrief. -*- lexical-binding: t; -*-
;; Copyright (C) 1994-2021 Free Software Foundation, Inc.
;; Author: Werner Fink <werner@suse.de>
;; Maintainer: auctex-devel@gnu.org
;; Keywords: tex
;; This file is part of AUCTeX.
;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING. If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.
;;; Commentary:
;; LaTeX Class: dinbrief.cls
;;; Code:
(require 'tex)
(require 'latex)
(TeX-add-style-hook
"dinbrief"
(lambda ()
(add-hook 'LaTeX-document-style-hook
#'LaTeX-dinbrief-style)
(LaTeX-add-environments
'("letter" LaTeX-dinbrief-env-recipient)
"dinquote")
(TeX-add-symbols
'("address" "Absender")
'("postremark" "Postvermerk")
'("date" "Datum")
'("subject" "Betreff")
'("handling" "Behandlungsvermerk")
'("cc" "Verteiler")
'("place" "Heutiger Ort")
"makelabels"
"nowindowrules"
"windowrules"
"nowindowtics"
"windowtics"
"disabledraftstandard"
"enabledraftstandard"
"centeraddress"
"normaladdress"
'("encl" "Anlagen: ")
'("backaddress" "Retouradresse")
'("signature" "Unterschrift")
'("opening" "Anrede")
'("closing" "Schluss")))
TeX-dialect)
(defmacro LaTeX-dinbrief-insert (&rest args)
"Insert text ignoring active markers."
`(progn (if mark-active (deactivate-mark))
(insert ,@args)))
(defun LaTeX-dinbrief-style ()
"Insert some useful packages for writing german letters."
;; COMPATIBILITY for EMACS<26
(let ((func (if (fboundp 'indent-relative-first-indent-point)
#'indent-relative-first-indent-point
;; Stay away from using #' to avoid compiler warning.
'indent-relative-maybe)))
(save-excursion
(goto-char (point-min)) ; insert before \begin{document}
(if (re-search-forward ".begin.document." (point-max) t)
(beginning-of-line 1))
(open-line 2)
(funcall func)
(LaTeX-dinbrief-insert TeX-esc "usepackage"
LaTeX-optop "latin1,utf8" LaTeX-optcl
TeX-grop "inputenc" TeX-grcl)
(newline-and-indent)
(LaTeX-dinbrief-insert TeX-esc "usepackage"
LaTeX-optop "T1" LaTeX-optcl
TeX-grop "fontenc" TeX-grcl)
(funcall func)
(LaTeX-dinbrief-insert TeX-esc "usepackage"
TeX-grop "ngerman" TeX-grcl))
(TeX-run-style-hooks "inputenc" "fontenc" "ngerman")))
(defun LaTeX-dinbrief-env-recipient (environment)
"Insert ENVIRONMENT and prompt for recipient and address."
(let ((sender (LaTeX-dinbrief-sender))
(recipient (TeX-read-string "Empfänger: "))
(address (LaTeX-dinbrief-recipient))
(date (TeX-read-string "Datum: " (LaTeX-dinbrief-today)))
(postremark (TeX-read-string "Postvermerk: "))
(fenster (TeX-read-string "Fenster (ja/nein): "))
(vermerk (TeX-read-string "Behandlungsvermerk: "))
(verteil (TeX-read-string "Verteiler: "))
(betreff (TeX-read-string "Betreff: "))
(opening (TeX-read-string "Anrede: "))
(closing (TeX-read-string "Schluss: "))
(signature (TeX-read-string "Unterschrift: "))
(anlage (TeX-read-string "Anlagen: "))
;; COMPATIBILITY for EMACS<26
(func (if (fboundp 'indent-relative-first-indent-point)
#'indent-relative-first-indent-point
;; Stay away from using #' to avoid compiler warning.
'indent-relative-maybe)))
(if (string= fenster "ja")
(progn
(LaTeX-dinbrief-insert TeX-esc "enabledraftstandard")
(newline-and-indent)
(LaTeX-dinbrief-insert TeX-esc "centeraddress")
(newline-and-indent)
(LaTeX-dinbrief-insert TeX-esc "nowindowrules")
(newline-and-indent)
(LaTeX-dinbrief-insert TeX-esc "windowtics")
(newline-and-indent)
(let ((retouradr (TeX-read-string "Retouradresse: " sender)))
(newline-and-indent)
(if (not (zerop (length retouradr)))
(progn
(if mark-active (deactivate-mark))
(LaTeX-dinbrief-insert TeX-esc "backaddress" TeX-grop retouradr TeX-grcl)
(newline-and-indent)))))
(LaTeX-dinbrief-insert TeX-esc "enabledraftstandard")
(newline-and-indent)
(LaTeX-dinbrief-insert TeX-esc "centeraddress")
(newline-and-indent)
(LaTeX-dinbrief-insert TeX-esc "nowindowrules")
(newline-and-indent)
(LaTeX-dinbrief-insert TeX-esc "windowtics"))
(newline-and-indent)
(if (not (zerop (length signature)))
(progn
(LaTeX-dinbrief-insert TeX-esc "signature" TeX-grop signature TeX-grcl)
(newline-and-indent)))
(if (not (zerop (length date)))
(progn
(LaTeX-dinbrief-insert TeX-esc "date" TeX-grop date TeX-grcl)
(newline-and-indent)))
(newline-and-indent)
(let ((indentation (current-column)))
(LaTeX-insert-environment
environment
(concat TeX-grop recipient
(if (not (zerop (length address)))
(concat
(if (not (zerop (length recipient)))
(concat " " TeX-esc TeX-esc " "))
address))
TeX-grcl))
(save-excursion ; Fix indentation of address
(if (search-backward TeX-grcl nil 'move)
(let ((addr-end (point-marker)))
(if (search-backward TeX-grop nil 'move)
(let ((addr-column (current-column)))
(while (search-forward
(concat TeX-esc TeX-esc)
(marker-position addr-end) 'move)
(progn
(newline)
(indent-to addr-column)))))
(set-marker addr-end nil))))
(LaTeX-dinbrief-insert "\n")
(indent-to indentation))
(if (not (zerop (length postremark)))
(progn
(LaTeX-dinbrief-insert TeX-esc "postremark" TeX-grop postremark TeX-grcl)
(newline-and-indent)))
(if (not (zerop (length betreff)))
(progn
(LaTeX-dinbrief-insert TeX-esc "subject" TeX-grop)
(LaTeX-dinbrief-insert betreff TeX-grcl)
(newline-and-indent)))
(if (not (zerop (length vermerk)))
(progn
(LaTeX-dinbrief-insert TeX-esc "handling" TeX-grop vermerk TeX-grcl)
(newline-and-indent)))
(if (not (zerop (length verteil)))
(progn
(LaTeX-dinbrief-insert TeX-esc "cc" TeX-grop verteil TeX-grcl)
(newline-and-indent)))
(if (not (zerop (length anlage)))
(progn
(LaTeX-dinbrief-insert TeX-esc "encl" TeX-grop anlage TeX-grcl)
(newline-and-indent)))
(LaTeX-dinbrief-insert TeX-esc "opening"
TeX-grop
(if (zerop (length opening))
(concat TeX-esc " ")
opening)
TeX-grcl "\n")
(funcall func)
(save-excursion
(LaTeX-dinbrief-insert "\n" TeX-esc "closing"
TeX-grop
(if (zerop (length closing))
(concat TeX-esc " ")
closing)
TeX-grcl "\n")
(funcall func))))
(defun LaTeX-dinbrief-sender ()
"Read and write the senders address."
(interactive)
(let ((name (TeX-read-string "Absender: " (user-full-name)))
(str (TeX-read-string "Meine Strasse: "))
(ort (TeX-read-string "Mein Wohnort: ")))
(if (not (zerop (length name)))
(progn
(goto-char (point-min)) ; insert before \end{document}
(if (re-search-forward ".end.document." (point-max) t)
(beginning-of-line 1))
(forward-line -1)
(LaTeX-dinbrief-insert TeX-esc "address" TeX-grop name)
(if (not (zerop (length str)))
(progn
(LaTeX-dinbrief-insert " " TeX-esc TeX-esc)
(newline-and-indent)
(LaTeX-dinbrief-insert str)))
(if (not (zerop (length ort)))
(progn
(LaTeX-dinbrief-insert " " TeX-esc "par")
(newline-and-indent)
(LaTeX-dinbrief-insert ort)))
(LaTeX-dinbrief-insert TeX-grcl)
(newline-and-indent)
(concat name ", " str ", " ort)))))
(defun LaTeX-dinbrief-recipient ()
"Read and return the recipient address."
(interactive)
(let ((str (TeX-read-string "Wohnhaft in Strasse: "))
(ort (TeX-read-string "Aus der Ortschaft: ")))
(if (not (zerop (length str)))
(if (not (zerop (length ort)))
(concat str " " TeX-esc TeX-esc " " ort)
str)
(if (not (zerop (length ort)))
ort))))
(defun LaTeX-dinbrief-today ()
"Return a string representing todays date according to flavor."
(interactive)
(let ((ctime-string (current-time-string))
(month-alist '(("Jan" . "Januar")
("Feb" . "Februar")
("Mar" . "M\\\"arz")
("Apr" . "April")
("May" . "Mai")
("Jun" . "Juni")
("Jul" . "Juli")
("Aug" . "August")
("Sep" . "September")
("Oct" . "Oktober")
("Nov" . "November")
("Dec" . "Dezember"))))
(string-match
"^\\S-+\\s-+\\(\\S-+\\)\\s-+\\(\\S-+\\)\\s-+\\S-+\\s-+\\(\\S-+\\)"
ctime-string)
(let ((year (substring ctime-string (match-beginning 3) (match-end 3)))
(month (substring ctime-string (match-beginning 1) (match-end 1)))
(day (substring ctime-string (match-beginning 2) (match-end 2)))
(place (TeX-read-string "Heutiger Ort: ")))
(if (assoc month month-alist)
(progn
(setq month (cdr (assoc month month-alist)))
(if (> 2 (length day))
(setq day (concat "0" day)))))
(format "%s, den %s. %s %s" place day month year))))
;;; dinbrief.el ends here
|