2

The KOMA-script bundle contains a package called scrjura and I'm using it to draft contracts.

The command for the standard section in contracts is \Clause{title=<title heading>}. Basically, I'd like to get an extra kind of section:

If the package scrjura is loaded in the preamble, I'd like to call this command the same way than other section commands: C-c C-s, the prompt of Emacs asks "Level: (default section)" and then select which one I'd like to use (section, Clause, subsection, ...) and then get the question "Title:", I type the title of the clause, the prompt of Emacs changes to "Label:", and if I choose "Clause" as level, the whole label prompt should be "Label: CLA:title-heading".

The desired output in my *.tex-file is:

\Clause{title=title heading}
\label{CLA:title-heading}

How do I set this up?

Even better: if the text "title heading" contains a comma (","), the whole of title heading needs extra brackets: \Clause{title={title, and foo}}. But this would be the cherry upon the chocolate, if you can say that in English.


MWE for a contract with a fairly recent scrjura:

\documentclass[pagesize, english, fontsize=12pt, parskip=half]{scrartcl}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}
\usepackage{babel, scrjura, xspace}


\title{Sicherheitsbestellung}
\subtitle{gag}
\date{}

\begin{document}
\maketitle

\begin{contract}
  \Clause{title=first title heading}

Some text. 


\Clause{title={second title, heading}}

And so on.

We get numbers here after two runs.

\end{contract}


\end{document}
  • Cannot write down an answer right now, but the relevant variables should be LaTeX-section-list and LaTeX-section-label. – giordano Aug 13 '15 at 13:01
  • Since \Clause uses a different syntax from the standard sectioning commands, you have also to change LaTeX-section-hook and define a function for this purpose. BTW: where is \Clause defined? If I load scrjura package and use \Clause{title=title heading} I get an "Undefined control sequence" error. – giordano Aug 13 '15 at 14:01
  • @giordano You need a fairly recent KOMA-script. The older command was \Paragraph{title= title heading}. If I had to define functions in Lisp, I'd need the better part of the summer to learn this. So your help would be appreciated very much. – Keks Dose Aug 13 '15 at 14:10
  • TeX Live 2015 just updated, I get always the same error. Probably I'm missing something, but I'd like to test on a concrete LaTeX document. Could you please add a proper MWE? – giordano Aug 13 '15 at 14:32
  • @giordano You have already helped me in the past, see here: tex.stackexchange.com/a/170338/4736 – Keks Dose Aug 13 '15 at 15:15
3

The best way to add support for a LaTeX package is to create a style file, see Automatic Extraction of New Things section of the AUCTeX manual. In this case creating the new style file doesn't suffice, you have also to add some code to your init file in order to support the new \Clause macro.

Style file

Create a file named scrjura.el in one of the directories listed in TeX-style-private (on GNU/Linux systems by default it's ~/.emacs.d/auctex/style). The content of the file is the following

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

With this file you essentially add the Clause sectioning macro to LaTeX-section-list.

Init file

Add also the following lines to your init file.

;; Add "CLA" label prefix for "Clause" macro
(eval-after-load "latex"  ; for plain AUCTeX
  '(add-to-list 'LaTeX-section-label '("Clause" . "CLA:")))
(eval-after-load "reftex-vars"  ; for RefTeX
  '(add-to-list 'reftex-label-alist '("Clause" 115 "CLA:" nil nil nil)))


(defun LaTeX-section-section ()
  "Hook to insert LaTeX section command into the file.
Insert this hook into `LaTeX-section-hook' after those hooks that set
the `name', `title', and `toc' variables, but before those hooks that
assume that the section is already inserted."
  ;; insert a new line if the current line and the previous line are
  ;; not empty (except for whitespace), with one exception: do not
  ;; insert a new line if the previous (or current, sigh) line starts
  ;; an environment (i.e., starts with `[optional whitespace]\begin')
  (unless (save-excursion
        (re-search-backward
         (concat "^\\s-*\n\\s-*\\=\\|^\\s-*" (regexp-quote TeX-esc)
             "begin")
         (line-beginning-position 0) t))
    (LaTeX-newline))
  (insert TeX-esc name)
  (cond ((null toc))
    ((zerop (length toc))
     (insert LaTeX-optop)
     (set-marker done-mark (point))
     (insert LaTeX-optcl))
    (t
     (insert LaTeX-optop toc LaTeX-optcl)))
  (insert TeX-grop)
  (if (zerop (length title))
      (set-marker done-mark (point)))
  (if (equal name "Clause")
      (insert "title="))
  (insert title TeX-grcl)
  (LaTeX-newline)
  ;; If RefTeX is available, tell it that we've just made a new section
  (and (fboundp 'reftex-notice-new-section)
       (reftex-notice-new-section)))

I've slightly redefined LaTeX-section-section to support \Clause, there is no need to write a new function from scratch (as I suggested previously in comments).

  • I get »Symbol's value as variable is void: LaTeX-section-label«, going to look for an error. – Keks Dose Aug 13 '15 at 17:54
  • @KeksDose Fixed ;-) – giordano Aug 13 '15 at 18:01
  • load-with-code-conversion: End of file during parsing: /home/AW/.emacs Never got this error, however, you seem to be really close to a solution, thank you so much. Hm, did I forget to copy a bracket? And is it really (insert TeX-grop) – Keks Dose Aug 13 '15 at 18:22
  • Well, no, I don't get that error when loading my init file and check-parens doesn't complain (what do you get with M-x check-parens RET?) :-/ Actually I don't know where it may come from (differently from the other error, I often forget to wrap an eval-after-load around add-to-list when I don't test the whole code). And yes, (insert TeX-grop) is correct. – giordano Aug 13 '15 at 19:27
  • For some reason, I get \Clause{heading}, instead of \Clause{title=heading}. But M-x check-parens RET revealed a missing ")", so the error of my last comment is gone. – Keks Dose Aug 13 '15 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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