AUCTeX Sync -- New Style Files
[packages] / xemacs-packages / auctex / style / paracol.el
1 ;;; paracol.el --- AUCTeX style for `paracol.sty' (v1.32)
2
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5 ;; Author: Arash Esbati <arash@gnu.org>
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Created: 2016-05-26
8 ;; Keywords: tex
9
10 ;; This file is part of AUCTeX.
11
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 ;; 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; This file adds support for `paracol.sty' (v1.32) from 2015/10/10.
30 ;; `paracol.sty' is part of TeXLive.
31
32 ;; `paracol.sty' provides an environment (paracol) and a command
33 ;; (\switchcolumn) which take a star as the second (!) optional
34 ;; argument.  In order to make the input process easier for the users,
35 ;; this style provides the environment `paracol*' and the command
36 ;; `switchcolumn*' in the list of completion after entering C-c C-e or
37 ;; C-c C-m (or C-c RET).
38
39 ;; Further, `\switchcolumn' takes a third optional argument containing
40 ;; text which will be inserted spanned over the columns.  This style
41 ;; does not ask for this argument.  If you need it, just enter it by
42 ;; hand after the completion.  This is a deliberate decision since I
43 ;; think that over the time, the annoyance factor of hitting `RET'
44 ;; will be larger than the number of times where this argument is
45 ;; actually used.
46
47 ;;; Code:
48
49 (defun TeX-arg-paracol-switchcolumn* (optional)
50   "Query and insert the column argument of \\switchcolum macro.
51 If OPTIONAL is non-nil, insert the result in square brackets."
52   (let ((col (TeX-read-string
53               (TeX-argument-prompt optional nil "Column"))))
54     (when (and col (not (string= col "")))
55       (save-excursion
56         (backward-char 1)
57         (TeX-argument-insert col optional)))))
58
59 (TeX-add-style-hook
60  "paracol"
61  (lambda ()
62
63    (LaTeX-add-environments
64     ;; 7.1 Environment paracol
65     ;; \begin{paracol}[numleft]{num}[text] body \end{paracol}
66     ;; \begin{paracol}[numleft]*{num}[text] body \end{paracol}
67     '("paracol" [ "Number left" ] "Number of columns" [ "Text across columns" ] )
68     '("paracol*"
69       (lambda (_env)
70         (let ((numleft (TeX-read-string
71                         (TeX-argument-prompt  t  nil "Number left")))
72               (numcol  (TeX-read-string
73                         (TeX-argument-prompt nil nil "Number of columns")))
74               (txt     (TeX-read-string
75                         (TeX-argument-prompt  t  nil "Text across columns"))))
76           (LaTeX-insert-environment
77            ;; Simply feed the function with "paracol", other option is
78            ;; something like:
79            ;; (replace-regexp-in-string (regexp-quote "*") "" env)
80            "paracol"
81            (concat
82             (when (and numleft (not (string= numleft "")))
83               (format "[%s]" numleft))
84             "*"
85             (format "{%s}" numcol)
86             (when (and txt (not (string= txt "")))
87               (format "[%s]" txt)))))))
88
89     ;; 7.2 Column-Switching Command and Environments
90     ;; \begin{column} body \end{column}
91     ;; \begin{column*}[text] body \end{column*}
92     '("column")
93     '("column*" [ "Text across columns" ] )
94
95     ;; \begin{nthcolumn}{col} body \end{nthcolumn}
96     ;; \begin{nthcolumn*}{col}[text] body \end{nthcolumn*}
97     '("nthcolumn" "Column")
98     '("nthcolumn*" "Column" [ "Text across columns" ] )
99
100     ;; \begin{leftcolumn} body \end{leftcolumn}
101     ;; \begin{leftcolumn*}[text] body \end{leftcolumn*}
102     ;; \begin{rightcolumn} body \end{rightcolumn}
103     ;; \begin{rightcolumn*}[text] body \end{rightcolumn*}
104     '("leftcolumn")
105     '("leftcolumn*" [ "Text across columns" ] )
106     '("rightcolumn")
107     '("rightcolumn*" [ "Text across columns" ] ))
108
109    (TeX-add-symbols
110     ;; 7.2 Column-Switching Command and Environments
111     ;; \switchcolumn[col]
112     ;; \switchcolumn[col]*[text]
113     '("switchcolumn" [ "Column" ] )
114     '("switchcolumn*" [ TeX-arg-paracol-switchcolumn* ] )
115     '("thecolumn")
116     '("ensurevspace" TeX-arg-length)
117
118     ;; 7.3 Commands for Column and Gap Width
119     ;; \columnratio{r0, r1, ... , rk}[r0', r1', ... , rk']
120     '("columnratio" "Fraction(s)" [ "Fraction(s)" ] )
121
122     ;; \setcolumnwidth{s0, s1, ... , sk}[s0', s1', ... , sk']
123     ;; with s as width/gap
124     '("setcolumnwidth" "Width/Gap" [ "Width/Gap" ] )
125
126     ;; 7.4 Commands for Two-Sided Typesetting and Marginal Note Placement
127     ;; \twosided[t1t2 ... tk]
128     '("twosided" [ "Features (combination of p, c, m, b)" ])
129
130     ;; \marginparthreshold{k}[k']
131     '("marginparthreshold" "Number of columns" [ "Number of columns" ] )
132
133     ;; 7.5 Commands for Counters
134     ;; \globalcounter{ctr}
135     ;; \globalcounter*
136     '("globalcounter" TeX-arg-counter)
137     '("globalcounter*")
138
139     ;; \localcounter{ctr}
140     '("localcounter" TeX-arg-counter)
141
142     ;; \definethecounter{ctr}{col}{rep}
143     '("definethecounter" TeX-arg-counter "Column" t)
144
145     ;; \synccounter{ctr}
146     '("synccounter" TeX-arg-counter)
147     '("syncallcounters")
148
149     ;; 7.6 Page-Wise Footnotes
150     '("footnotelayout"
151       (TeX-arg-eval completing-read
152                     (TeX-argument-prompt optional nil "Layout")
153                     '("c" "m" "p")))
154
155     ;; \footnote*[num]{text}
156     ;; \footnotemark*[num]
157     ;; \footnotetext*[num]{text}
158     ;; Copied from `latex.el'
159     '("footnote*"
160       (TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil)
161       t)
162     '("footnotetext*"
163       (TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil)
164       t)
165     '("footnotemark*"
166       (TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil))
167
168     '("fncounteradjustment" 0)
169     '("nofncounteradjustment" 0)
170
171     ;; 7.7 Commands for Coloring Texts and Column-Separating Rules
172     ;; \columncolor[mode]{color}[col]
173     ;;
174     ;; This clashes if colortbl.el is loaded since it provides a
175     ;; command with the same name but different arguments.  We add
176     ;; the command only here but not for fontification
177     '("columncolor" (TeX-arg-conditional (member "xcolor" (TeX-style-list))
178                                          (TeX-arg-xcolor)
179                                        (TeX-arg-color))
180       [ "Column" ] )
181
182     ;; \normalcolumncolor[col]
183     '("normalcolumncolor" [ "Column" ] )
184     '("coloredwordhyphenated" 0)
185     '("nocoloredwordhyphenated" 0)
186
187     ;; \colseprulecolor[mode]{color}[col]
188     ;; \normalcolseprulecolor[col]
189     '("colseprulecolor" (TeX-arg-conditional (member "xcolor" (TeX-style-list))
190                                              (TeX-arg-xcolor)
191                                            (TeX-arg-color))
192       [ "Column" ] )
193     '("normalcolseprulecolor" [ "Column" ] )
194
195     ;; 7.8 Commands for Background Painting
196     ;; \backgroundcolor{region}[mode]{color}
197     ;; \backgroundcolor{region(x0,y0)}[mode]{color}
198     ;; \backgroundcolor{region(x0,y0)(x1,y1)}[mode]{color}
199     '("backgroundcolor"
200       (TeX-arg-eval completing-read
201                     (TeX-argument-prompt optional nil "Region")
202                     '("c" "g" "s" "f" "n" "p" "t" "b" "l" "r"
203                       "C" "G" "S" "F" "N" "P" "T" "B" "L" "R"))
204       (TeX-arg-conditional (member "xcolor" (TeX-style-list))
205                            (TeX-arg-xcolor)
206                          (TeX-arg-color)))
207
208     ;; \nobackgroundcolor{region}
209     '("nobackgroundcolor"
210       (TeX-arg-eval completing-read
211                     (TeX-argument-prompt optional nil "Region")
212                     '("c" "g" "s" "f" "n" "p" "t" "b" "l" "r"
213                       "C" "G" "S" "F" "N" "P" "T" "B" "L" "R")))
214
215     ;; \resetbackgroundcolor
216     '("resetbackgroundcolor" 0)
217
218     ;; 7.9 Control of Contents Output
219     ;; \addcontentsonly{file}{col}
220     '("addcontentsonly"
221       (TeX-arg-eval completing-read
222                     (TeX-argument-prompt optional nil "Content file")
223                     '("toc" "lof" "lot"))
224       "Column")
225
226     '("flushpage" 0))
227
228    ; \switchcolumn should get its own line:
229    (LaTeX-paragraph-commands-add-locally "switchcolumn")
230
231    ;; Fontification
232    (when (and (featurep 'font-latex)
233               (eq TeX-install-font-lock 'font-latex-setup))
234                               ;; FIXME: Syntax is \switchcolumn[num]*[text].
235                               ;; font-latex.el doesn't handle the case
236                               ;; where `*' comes after the first `['.
237                               ;; Therefore, we use this compromise to
238                               ;; get something fontified at least.
239      (font-latex-add-keywords '(("switchcolumn"                 "*["))
240                               'textual)
241      (font-latex-add-keywords '(("flushpage"                    "*["))
242                               'warning)
243      (font-latex-add-keywords '(("footnote"                     "*[{")
244                                 ("footnotemark"                 "*[")
245                                 ("footnotetext"                 "*[{"))
246                               'reference)
247      (font-latex-add-keywords '(("ensurevspace"                 "{")
248                                 ("columnratio"                  "{[")
249                                 ("setcolumnwidth"               "{[")
250                                 ("twosided"                     "[")
251                                 ("marginparthreshold"           "{[")
252                                 ;; FIXME: Syntax is
253                                 ;; \globalcounter{ctr} or
254                                 ;; \globalcounter* We ignore `{' since
255                                 ;; font-latex.el doesn't handle a
256                                 ;; missing bracket nicely.
257                                 ("globalcounter"                "*")
258                                 ("definethecounter"             "{{{")
259                                 ("synccounter"                  "{")
260                                 ("syncallcounters"              "")
261                                 ("footnotelayout"               "{")
262                                 ("fncounteradjustment"          "")
263                                 ("nofncounteradjustment"        "")
264                                 ("normalcolumncolor"            "[")
265                                 ("coloredwordhyphenated"        "")
266                                 ("nocoloredwordhyphenated"      "")
267                                 ("colseprulecolor"              "[{[")
268                                 ("normalcolseprulecolor"        "[")
269                                 ("backgroundcolor"              "{[{")
270                                 ("nobackgroundcolor"            "{")
271                                 ("resetbackgroundcolor"         "")
272                                 ("addcontentsonly"              "{{"))
273                               'function)))
274  LaTeX-dialect)
275
276 (defvar LaTeX-paracol-package-options nil
277   "Package options for the paracol package.")
278
279 ;;; paracol.el ends here