1

There is a new LaTeX package: "contract". Inside a contract environment there are two new sectioning commands:

\Clause[optionlist]
\SubClause[optionlist]

The section command of Clause is on the level of a section, the SubSection is on the level of a subsection.

There are only optional arguments! So: \Clause{something}doesn't exist.

The most used command will be

\Clause[title=some clausetitle]

Q: Can you help me to make Emacs aware of this sectioning command in LaTeX/PS major mode (I guess this is done by AUCTeX)? If the contract package is loaded, I'd like to have a sectioning command \Clause[].

Please be aware, that there is a package scrjura which comes with a sectioning command \Clause{}. Unfortunately I have to use either scrjura or contract (never both in the same file, of course).

Almost ten years ago I've been asking a similar question. So I wrote a style file called "contract.el" and saved it besides the former "scrjura.el" in ~/.emacs.d/auctex/style.

Style files:

scrjura.el:

(TeX-add-style-hook
 "scrjura"
 (lambda ()
   (LaTeX-section-list-add-locally '(("Clause" 3)
            ("SubClause" 4)      
                     ("subsection" 4)
                     ("subsubsection" 5)
                     ("paragraph" 6)
                     ("subparagraph" 7)))
   (TeX-run-style-hooks
    "scrkbase"
    "tocbasic"))
 LaTeX-dialect)

contract.el:

(TeX-add-style-hook
 "contract"
 (lambda ()
   (LaTeX-section-list-add-locally '(("Clause" 3)
            ("SubClause" 4)      
                     ("subsection" 4)
                     ("subsubsection" 5)
                     ("paragraph" 6)
                     ("subparagraph" 7)))
   (TeX-run-style-hooks
    "scrkbase"
    "tocbasic"))
 LaTeX-dialect)

Having both style files doubles the output after C-=, I get the name of each clause twice. Q: If somebody could help me to get rid of double lines.

MWE:

\documentclass[ngerman]{scrartcl}

\usepackage{babel}
\usepackage{contract}

\begin{document}
\begin{contract}
  \Clause[title=whatever first]

  Some text.

  Next paragraph.

  \Clause[title= Closing]

  Whatever more text. 
\end{contract}
\end{document}
1
  • One question per post, please.
    – Drew
    Commented Jun 11 at 17:09

1 Answer 1

1

I don't think it is possible to hook the macro \Clause which takes an optional key-val argument into the machinery how AUCTeX inserts sectioning commands without a bigger surgery. Therefore I suggest you go the standard way by doing C-c C-m Clause RET where the corresponding AUCTeX style file can look like this (which is 0-tested):

;;; contract.el --- AUCTeX style for `contract.sty' (v0.91)  -*- lexical-binding: t; -*-

(defconst LaTeX-contract-clause-key-val
  '(("dummy")
    ("head")
    ("nohead")
    ("notocentry")
    ("number")
    ("preskip")
    ("postskip")
    ("title")
    ("tocentry"))
  "Key=val options for the \\Clause macro.")

(TeX-add-style-hook
 "contract"
 (lambda ()

   (LaTeX-add-environments
    '("contract"))

   (TeX-add-symbols
    '("Clause"
      [TeX-arg-key-val LaTeX-contract-clause-key-val])
    '("SubClause"
      [TeX-arg-key-val LaTeX-contract-clause-key-val])
    "Clauseformat"
    "thepar"
    "parformat"
    "parformatseparation"
    "withoutparnumber"
    '("ellipsispar" ["Number of paragraphs to omit"])
    "parellipsis")

   (let ((macs '("refL" "refS" "refN" "refClause" "refClauseN"
                 "refPar" "refParL" "refParS" "refParN"
                 "refSentence" "refSentenceL"" refSentenceS" "refSentenceN")))
     (dolist (mac macs)
       (TeX-add-symbols `(,mac TeX-arg-ref)))
     (when (and (featurep 'font-latex)
                (eq TeX-install-font-lock 'font-latex-setup))
       (font-latex-add-keywords
        (mapcar (lambda (x) (list x "{")) macs)
        'reference)))

   (LaTeX-paragraph-commands-add-locally '("Clause" "SubClause"))

   (LaTeX-add-counters "par" "sentence")

   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("contractSetup" "{")
                                ("ellipsispar"   "["))
                              'function)
     (font-latex-add-keywords '(("Clause" "["))
                              'sectioning-2)
     (font-latex-add-keywords '(("SubClause" "["))
                              'sectioning-3)))
 TeX-dialect)

(defconst LaTeX-contract-package-options-list
  (let ((len (mapcar (lambda (x) (concat TeX-esc (car x)))
                     (LaTeX-length-list))))
    `(("juratotoc" ("true" "false" "number"))
      ("juratocindent" ,len)
      ("juratocnumberwidth" ,len)
      ("contract")
      ("juratitlepagebreak" ("true" "false"))
      ("clausemark" ("both" "false" "forceboth" "forceright" "right"))
      ("parnumber" ("true" "false" "auto" "manual"))
      ("ref" ("long" "numeric"
              "clauseonly" "onlyclause" "ClauseOnly" "OnlyClause"
              "parlong" "longpar" "ParL"
              "parnumeric" "numericpar" "ParN"
              "paroff" "nopar"
              "parshort" "shortpar" "ParS" "sentencelong" "longsentence"
              "SentenceL"
              "sentencenumeric" "numericsentence" "SentenceN"
              "sentenceoff" "nosentence" "sentenceshort" "shortsentence"
              "SentenceS"
              "short"))))
  "Alist of package options for the contract package.")

(defun LaTeX-contract-package-option ()
  "Read the contract package options from the user."
  (TeX-read-key-val t LaTeX-contract-package-options-list))

;;; contract.el ends here

I suggest you take the above to auctex-devel mailing list and report back how it works. Once the style is really operational, it can be added to AUCTeX distro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.