auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX-devel] [PATCH] Add cleveref style support.


From: Tassilo Horn
Subject: Re: [AUCTeX-devel] [PATCH] Add cleveref style support.
Date: Tue, 14 Oct 2014 11:36:21 +0200
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Matthew Leach <address@hidden> writes:

Hi Matthew,

> This patch adds a new style file for cleveref support.  I've included
> support for the most used cleveref macros, a new argument function
> that prompts the user for a series of labels and package options.

Nice, thanks.  In order to add this style to AUCTeX, you need to assign
copyright to the FSF.  If you are willing to do so, please fill out this
form

  
http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/Copyright/request-assign.future;hb=HEAD

and sent it to address@hidden with me in the Cc.  It's best if you name
Emacs as program you've contributed to since a copyright assignment for
Emacs also covers AUCTeX but not the other way round.

> I notice that \cref and friends aren't highlighted as keywords by
> font-lock.  Do I need to provide a hints to font-lock, such as is done
> in style/babel.el?

Yes, exactly.  You want to add \cref and friends to font-latex's
'reference class.  Have a look at style/hyperref.el which does the same
below the ;; Fontification comment.

> Any comments welcome.

See below.

> +(defun TeX-arg-multiple-labels (optional &optional prompt definition)

If this function is in the cleverref style, then it should start with
TeX-arg-cleverref-*.  If it was generally useful also for other styles,
then the name would be ok and we could add it to tex.el.  You could
check the other styles if multiple labels are queried and inserted, too.

> +  "Prompt for a series of labels completing with known labels.
> +If OPTIONAL is non-nil, insert the resulting value as an optional
> +argument, otherwise as a mandatory one.  Use PROMPT as the prompt
> +string.  If DEFINITION is non-nil, add each chosen label to the
> +list of defined labels."
> +  (let ((all-refs "")
> +        (first-ref t))
> +    (while
> +        (progn
> +          (let ((label (completing-read
> +                        (concat (TeX-argument-prompt optional prompt "Key" 
> (not first-ref))
> +                                (unless first-ref " (\"\" to finish): "))
> +                        (LaTeX-label-list))))
> +            (unless (string-equal "" label)
> +              (when definition
> +                (LaTeX-add-labels label))
> +              (setq all-refs
> +                    (concat all-refs (unless first-ref ",") label))
> +              (setq first-ref nil)
> +              t))))
> +    (TeX-argument-insert all-refs optional optional)))

This enter one label after the other in a loop approach is not very
convenient.  Use `TeX-completing-read-multiple' instead which reads
multiple elements as a comma-separated string.

> +(TeX-add-style-hook
> + "cleveref"
> + (lambda ()
> +   (TeX-add-symbols
> +    '("cref" TeX-arg-multiple-labels)
> +    '("Cref" TeX-arg-multiple-labels)
> +    '("crefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
> +    '("Crefrange" (TeX-arg-label "key (first)") (TeX-arg-label "Key (last)"))
> +    '("cpageref" TeX-arg-multiple-labels)
> +    '("Cpageref" TeX-arg-multiple-labels)
> +    '("cpagerefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key 
> (last)"))
> +    '("Cpagerefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key 
> (last)"))
> +    '("cref*" TeX-arg-multiple-labels)
> +    '("Cref*" TeX-arg-multiple-labels)
> +    '("crefrange*" (TeX-arg-label "Key (first)") (TeX-arg-label "Key 
> (last)"))
> +    '("Crefrange*" (TeX-arg-label "Key (first)") (TeX-arg-label "Key 
> (last)"))))
> + LaTeX-dialect)

If some of these macros are rarely useful for the average LaTeX user,
you can declare them to be expert commands using
`TeX-declare-expert-macros'.  Have a look at style/metalogo.el for an
example.

Bye,
Tassilo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]