auctex-devel
[Top][All Lists]

## Re: [AUCTeX-devel] insert a label with the file name as suffix.

 From: Arash Esbati Subject: Re: [AUCTeX-devel] insert a label with the file name as suffix. Date: Thu, 04 May 2017 18:27:25 +0200 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2

Uwe Brauer <address@hidden> writes:

> Now for the exam class, Arash proposed to use
>
> (defun LaTeX-exam-insert-label (_optional &optional name type)
>   "Indent the line and query/insert a label incl. the \"\\label\" macro.
> Arguments NAME and TYPE are the same as for the function
> LaTeX-label'.  OPTIONAL is ignored."
>   (indent-according-to-mode)
>   (let ((currenv (LaTeX-current-environment)))
>     (LaTeX-label (or name currenv) (or type 'environment))))
>
> Which does not use anything from reftex. I looked at reftex-label and it
> is a bit complicated to say the least.

Hi Uwe,

have a look at the defintion of LaTeX-label': it looks if the variable
LaTeX-label-function' contains a function and then runs it for label
insertion.  I have (setq reftex-plug-into-AUCTeX t)' in my .emacs and
it gives me:

,----[ C-h v LaTeX-label-function RET ]
| LaTeX-label-function is a variable defined in ‘latex.el’.
| Its value is ‘reftex-label’
| Original value was nil
|
|   This variable may be risky if used as a file-local variable.
|
| Documentation:
| *A function inserting a label at point or returning a label string.
| [...]
----

> So I would appreciate if someone had an idea how to modify
> LaTeX-exam-insert-label that is behaves the way I just
> described. probably I could hack something up using concat and friends
> but I bet there are more elegant solutions.

I think the issue is somewhere else: In exam.el,
LaTeX-exam-insert-label' is used for "titledquestion" and
"bonustitledquestion".  IIRC, you have to add these environments to
LaTeX-label-alist' and reftex-label-alist' in order to get what you
want, e.g.

and

`