Hi Arash !
Am Montag, 22. August 2016, 19:56:42 CEST schrieb Arash Esbati:
> AW <[email protected]> writes:
...
> > I use these commands for a kind of abbreviated links, see here (only if
> > you
> > are interested): http://tex.stackexchange.com/a/325871/4736
> >
...
> The final scenario is that \Label is only included after sectioning
> commands?
Yes!
> 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".
However, I often use reftex to get e.g. a table of contents in Emacs (C-c = ).
Difficult.
>
> --8<---------------cut here---------------start------------->8---
> ... nice code...
> With Reftex, the job is done by `reftex-label' and the modification
> above does not work anymore. Altering `reftex-label' is something you
> want to do with the next flood ;-)
Reftex seems to be able to deal with varioref. Maybe we can steal some ideas
there.
> My suggestion would be to hack
> `LaTeX-abbrev-refs-section-label' to search back and replace \label with
> \Label or to do it on TeX level with a flag that \label expands to
> \Label after \section and to original \label otherwise.
Öh, äh, yes. Whut?
> > Maybe someone can write some lines on a rainy day?
>
> The forecast says no rain for the rest of the week ;-)
Yes, I'm on vacation in Netherlands and after some rainy days tomorrow the
nice weather is appreciated really!
>
> Best, Arash
Kind regards,
Alexander
(defun LaTeX-abbrev-refs-label (name &optional type)
"Insert a Label for NAME at point.
The optional TYPE argument can be either environment or section:
in the former case this function looks up `LaTeX-label-alist' to
choose which prefix to use for the label, in the latter case
`LaTeX-section-label' will be looked up instead. If TYPE is nil,
you will be always prompted for a label, with an empty default
prefix.
If `LaTeX-label-function' is a valid function, LaTeX label will
transfer the job to this function.
The inserted label is returned, nil if it is empty."
(let ((TeX-read-label-prefix
(cond
((eq type 'environment)
(cdr (assoc name LaTeX-label-alist)))
((eq type 'section)
(if (assoc name LaTeX-section-list)
(if (stringp LaTeX-section-label)
LaTeX-section-label
(and (listp LaTeX-section-label)
(cdr (assoc name LaTeX-section-label))))
""))
((null type)
"")
(t
nil)))
label)
(when (symbolp TeX-read-label-prefix)
(setq TeX-read-label-prefix (symbol-value TeX-read-label-prefix)))
(when TeX-read-label-prefix
(if (and (boundp 'LaTeX-label-function)
LaTeX-label-function
(fboundp LaTeX-label-function))
(setq label (funcall LaTeX-label-function name))
;; Use completing-read as we do with `C-c C-m \label RET'
(setq label (TeX-read-label t "What label" t))
;; No label or empty string entered?
(if (or (string= TeX-read-label-prefix label)
(string= "" label))
(setq label nil)
;; Modification start: Insert "Label" instead of "label"
(insert TeX-esc "Label" TeX-grop label TeX-grcl)) ; Modification end
(if label
(progn
(LaTeX-add-labels label)
label)
nil)))))
(defun LaTeX-abbrev-refs-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'."
(and (LaTeX-abbrev-refs-label name 'section)
(LaTeX-newline)))
(TeX-add-style-hook
"abbreviated-refs"
(lambda ()
(TeX-add-symbols
'("Label" TeX-arg-define-label)
'("myref" TeX-arg-ref))
;; Alter LaTeX-section-hook: Replace `LaTeX-section-label' w/
;; `LaTeX-abbrev-refs-section-label':
(make-local-variable 'LaTeX-section-hook)
(setq LaTeX-section-hook
'(LaTeX-section-heading
LaTeX-section-title
LaTeX-section-section
LaTeX-abbrev-refs-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)
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{abbrev-ref}[2016/08/22 LaTeX2e Package for abbreviated references]
\RequirePackage{zref-user, zref-counter}
\RequirePackage{expl3}
\setcounter{secnumdepth}{5} % fünf Ebenen
\renewcommand*{\thesection}{\Alph{section}.}
\renewcommand*{\thesubsection}{\Roman{subsection}.}
\renewcommand*{\thesubsubsection}{\arabic{subsubsection}.}
\renewcommand*{\theparagraph}{\alph{paragraph})}%)
\renewcommand*{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph})}
%\makeatletter
\zref@newprop{section}[1]{\the\c@section}
\zref@newprop{subsection}[1]{\the\c@subsection}
\zref@newprop{subsubsection}[1]{\the\c@subsubsection}
\zref@newprop{paragraph}[1]{\the\c@paragraph}
\zref@newprop{subparagraph}[1]{\the\c@subparagraph}
\zref@addprop{main}{section}
\zref@addprop{main}{subsection}
\zref@addprop{main}{subsubsection}
\zref@addprop{main}{paragraph}
\zref@addprop{main}{subparagraph}
\ExplSyntaxOn
\newcommand\myref[1]{%
\hyperref[#1]{%
\int_compare:nTF
{% A.-Ebene prüfen: sind wir auf dem gleichen Zweig?
\zref@extractdefault {#1} {section} {0} = \the\c@section
}
{ % Ja, wir sind auf dem gleichen Zweig
% Existiert eine weitere Ebene?
\int_compare:nTF
{\zref@extractdefault {#1} {subsection} {0} = 0}
% Wenn subsection 0 ist, also nicht existiert, dann muss section ausgegeben
% werden.
{
% \emph{Fehlerhafter Verweis}
\int_to_Alph:n {\zref@extractdefault {#1} {section} {0}}.
}
% Wenn dagegen subsection existiert, dann geht die Prüfung weiter:
{
% OK, weitere ebene existiert.
\int_compare:nTF % I.-Ebene
{
\zref@extractdefault {#1} {subsection} {0} = \the\c@subsection
}% Sind wir auf der gleichen I.-Ebene?
{% I.-Ebene: Gleiche Ebene
% Prüfung: gibt es eine weitere Ebene?
\int_compare:nTF
{\zref@extractdefault {#1} {subsubsection} {0} = 0}
{% Wenn 0, dann keine weitere Ebene und subsection ausgeben:
\int_to_Roman:n {\zref@extractdefault {#1} {subsection} {0}}.
}
{% OK, weitere Ebene existiert
\int_compare:nTF % subsubsection-Ebene
{% 1.-Ebene prüfen
\zref@extractdefault {#1} {subsubsection} {0} = \the\c@subsubsection
}
{% 1.-Ebene ist gleich
%Prüfung: gibt es eine weitere Ebene?
\int_compare:nTF % Gibt es eine a-Ebene?
{\zref@extractdefault {#1} {paragraph} {0} = 0}
{% Wenn 0, dann keine weitere Ebene und subsubsection ausgeben:
\int_to_arabic:n { \zref@extractdefault {#1} {subsubsection} {0}}.
}
{% Paragraph existiert:
\int_compare:nTF % a-Ebene prüfen
{
\zref@extractdefault {#1} {paragraph} {0} = \the\c@paragraph
}
{% a-Ebene ist gleich
% Prüfung: aa-Ebene vorhanden?
\int_compare:nTF %
{ \zref@extractdefault {#1} {subparagraph} {0} = 0}
%
{%( damit emacs happy ist
\int_to_alph:n {\zref@extractdefault {#1} {paragraph} {0} })
}
{% aa-Ebene vorhanden
\int_compare:nTF
{\zref@extractdefault {#1} {subparagraph} {0} = \the\c@subparagraph}
{\emph{Fehlerhafter VERWEIS}}
%( make emacs happy
{\int_to_alph:n { \zref@extractdefault {#1} {subparagraph} {0} }
\int_to_alph:n { \zref@extractdefault {#1} {subparagraph} {0} })
}
}
}
{% a-Ebene ist unterschiedlich (
\int_to_alph:n{\zref@extractdefault {#1} {paragraph} {0}})
}
}
}
{% 1.-Ebene ist unterschiedlich
\int_to_arabic:n{\zref@extractdefault {#1} {subsubsection} {0}}.
}
}% 3. Klammer Prüfung, ob subsection existiert (also wenn ja)
}
{% I.-Ebene: ungleich
% Also römische Nummer ausgeben
\int_to_Roman:n{\zref@extractdefault {#1} {subsection} {0}}.%
\int_compare:nTF%existiert die nächste Ebene?
{ \zref@extractdefault {#1} {subsubsection} {0} = 0 }
{}% = 0, subsubsection nicht vorhanden
{% ungleich 0
% also arabische Zahl ausgeben
\int_to_arabic:n { \zref@extractdefault {#1} {subsubsection} {0}}.
\int_compare:nTF%existiert die nächste Ebene paragraph?
{ \zref@extractdefault {#1} {paragraph} {0} = 0 }
{}% = 0, subsubsection nicht vorhanden
{% ungleich 0 (
\int_to_alph:n { \zref@extractdefault {#1} {paragraph} {0}})
}
% subpar Ebene vorhanden?
\int_compare:nTF
{ \zref@extractdefault {#1} {subparagraph} {0} = 0}
{}% ja, also existiert subpar nicht
{ %(
\int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}}
\int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}})
}
}
}% 3. Klammer I.-Ebene
}% 3. Klammer Prüfung, ob I. Ebene besteht.
}% 2. Klammer A.-Ebene
{% A.-Ebene: Ungleich
%ref is from other section
\int_to_Alph:n {\zref@extractdefault {#1} {section} {0}}.
\int_compare:nTF%existiert die nächste Ebene?
{ \zref@extractdefault {#1} {subsection} {0} = 0 }
{}% ja, erfüllt, keine subsection
{% subsection existiert:
\int_to_Roman:n {\zref@extractdefault {#1} {subsection} {0}}.
\int_compare:nTF%existiert die nächste Ebene?
{ \zref@extractdefault {#1} {subsubsection} {0} = 0 }
{}% = 0, subsubsection nicht vorhanden
{% ungleich 0
\int_to_arabic:n { \zref@extractdefault {#1} {subsubsection} {0} }.
\int_compare:nTF%existiert die nächste Ebene paragraph?
{ \zref@extractdefault {#1} {paragraph} {0} = 0 }
{}% = 0, paragraph nicht vorhanden
{% ungleich 0 (
\int_to_alph:n { \zref@extractdefault {#1} {paragraph} {0} })
\int_compare:nTF
{ \zref@extractdefault {#1} {subparagraph} {0} = 0}
{}% ja, also existiert subpar nicht
{% (
\int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}}
\int_to_alph:n {\zref@extractdefault {#1} {subparagraph} {0}})
}
}
}
}
}% 3. Klammer A.-Ebene
}% hyperref Klammer zu
}%Ende Befehlsdefinition myref
\ExplSyntaxOff
%\makeatother
\usepackage[]{hyperref}
\newcommand\Label[1]{\zlabel{#1}\label{#1}}
\endinput_______________________________________________
auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex