auctex
[Top][All Lists]
Advanced

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

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


From: AW
Subject: Re: [AUCTeX] Support for "\Label" and "\myref"
Date: Wed, 24 Aug 2016 15:56:20 +0200
User-agent: KMail/5.2.3 (Linux/4.7.1-1-default; KDE/5.24.0; x86_64; ; )

Hi Arash,

Am Dienstag, 23. August 2016, 09:20:26 CEST schrieb Arash Esbati:
> 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.

Flabbergasted. You let the whole machinery do the work and then change just 
the letter -- funny idea. 

I wrote some lines and tested it -- it works, I get \Label after sections. 

If I'm trying to put a label into running text, there is an error message:

reftex-nth-arg-wrapper: Wrong type argument: number-or-marker-p, nil

but I can live with this.

So: Thank you very much!

I'm looking for the same kind of support for the new "\myref", which should be 
treated exactly like "\ref" by Emacs.

You did a lot for me, so I hesitate to ask for more. What do you think, should 
I ask on tex.stackexchange and notify you about the question there?

Kind Regards,
Alexander

> 
> 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)
>        (LaTeX-newline))
>   (save-excursion
>     (re-search-backward (concat (regexp-quote TeX-esc) "label"))
>     (forward-char)
>     (delete-char 1)
>     (insert "L")))
> 
> (TeX-add-style-hook
>  "abbrev-ref"
>  (lambda ()
> 
>    (TeX-add-symbols
>     '("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
>        '(LaTeX-section-heading
>          LaTeX-section-title
>          LaTeX-section-section
>          LaTeX-abbrev-ref-section-label))
> 
>    ;; 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" "{"))
>                             'reference)))
>  LaTeX-dialect)
> 
> ;;; 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]