[Top][All Lists]

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

Re: [AUCTeX] Support for "\Label" and "\myref"

From: Arash Esbati
Subject: Re: [AUCTeX] Support for "\Label" and "\myref"
Date: Tue, 23 Aug 2016 09:20:26 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1

AW <address@hidden> writes:

> Am Montag, 22. August 2016, 19:56:42 CEST schrieb Arash Esbati:
>> AW <address@hidden> writes:
> ...
>> > I use these commands for a kind of abbreviated links, see here (only if
>> > you
>> > are interested):
>> > 
> ...
>> The final scenario is that \Label is only included after sectioning
>> commands?  
> Yes! 

Ok, thanks.

>> Within AUCTeX, i.e. without Reftex, you probably could get
>> away with a style file `abbreviated-refs.el' like this (untested!).
>> Function `LaTeX-section-label' is altered to
>> `LaTeX-abbrev-refs-section-label' and it calls `LaTeX-abbrev-refs-label'
>> instead of `LaTeX-label':
> OK, thank you very much!!!
> I simply put the tex-code I wrote into the file abbrev-ref.sty, which I 
> attach 
> here.
> Then I copied your code into abbrev-ref.el and saved it to the same place, a 
> temp directory.
> In this directory I opened a new *.tex file and tried to write an article. 
> But 
> after inserting a section, I just get the usual prompt and "\label". 

As I said, the code I sent only works when Reftex is disabled.

> Reftex seems to be able to deal with varioref. Maybe we can steal some ideas 
> there.

Not really, varioref.sty defines a series of referencing commands and
not a new command like \Label to define new anchors.  Or am I missing

>> My suggestion would be to hack
>> `LaTeX-abbrev-refs-section-label' to search back and replace \label with
>> \Label

The code below would also work with Reftex.  It is the easiest solution
comes to my mind if you only want \Label after sectioning commands.  The
function `LaTeX-abbrev-ref-section-label' does the same job as
`LaTeX-section-label' and then replaces "l" with "L" in \label.

I suggest you set the variable `TeX-style-private' in your init file, e.g.

    (setq TeX-style-private (expand-file-name "~/.emacs.d/styles/private"))

and save this code there as `abbrev-ref.el'.  Restart Emacs and open
your tex file with \usepackage{abbrev-ref}, hit C-c C-n, and then insert
a section with C-c C-s.

--8<---------------cut here---------------start------------->8---
(defun LaTeX-abbrev-ref-section-label ()
  "Hook to insert a label after the sectioning command.
Insert this hook into `LaTeX-section-hook' to prompt for a label to be
inserted after the sectioning command.

The behaviour of this hook is controlled by variable `LaTeX-section-label'.

Also, search back and replace \\label with \\Label."
  (and (LaTeX-label name 'section)
    (re-search-backward (concat (regexp-quote TeX-esc) "label"))
    (delete-char 1)
    (insert "L")))

 (lambda ()

    '("Label" TeX-arg-define-label)
    '("myref" TeX-arg-ref))

   ;; Alter LaTeX-section-hook: Replace `LaTeX-section-label' w/
   ;; `LaTeX-abbrev-ref-section-label':
   (make-local-variable 'LaTeX-section-hook)
   (setq LaTeX-section-hook

   ;; Cater Reftex support:
   (when (boundp 'reftex-label-alist)
     (add-to-list 'reftex-label-alist
                  '("\\Label{*}" nil nil nil nil) t))

   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("Label" "{")
                                ("myref" "{"))

;;; abbrev-ref.el ends here
--8<---------------cut here---------------end--------------->8---

> Yes, I'm on vacation in Netherlands and after some rainy days tomorrow the 
> nice weather is appreciated really!

Enjoy it!

Best, Arash

reply via email to

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