Am Mittwoch, 24. August 2016, 17:35:16 CEST schrieb Arash Esbati:
> Can you elaborate that?  With the code above, I press `C-c C-m myref
> RET' and go through the same procedure as with `ref'.

Hi,

I realised that KOMA-script already has "myref" as a variable, so I choose 
"secref" instead, we now have "seclabel" and "secref".

Attached I send the adapted abbrev-ref.sty and abbrev-ref.sty.

AucTeX asks for seclabel after any section, function like \label.

\secref does not trigger any action by AucTeX.

It's late today, I can't write a minimal .emacs just with the necessary 
commands to load AUCTeX and abbrev-ref.el. But I searched my .emacs and I 
don't mess with reftex, as far as I can see.

Thank you for your helping hand,

Regards,

Alexander

(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 \\seclabel.  The
search is limited to the sectioning command just inserted in
order not to replace any other \\label commands if no \\label is
inserted, e.g. after \\section*."
  (and (LaTeX-label name 'section)
       (LaTeX-newline))
  (let ((labelpos
         (save-excursion
           (re-search-backward (concat (regexp-quote TeX-esc) "label")
                               (save-excursion
                                 (re-search-backward (concat (regexp-quote TeX-esc) name)))
                               t))))
    (when labelpos
      (save-excursion
        (goto-char (1+ labelpos))
        (insert "sec")))))

(TeX-add-style-hook
 "abbrev-ref"
 (lambda ()

   (TeX-add-symbols
    '("seclabel" TeX-arg-define-label)
    '("secref" 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
                  '("\\seclabel{*}" nil nil nil nil) t))

   ;; Fontification
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("seclabel" "{")
                                ("secref"    "{"))
                              'reference)))
 LaTeX-dialect)

;;; abbrev-ref.el ends here
\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\secref[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\seclabel[1]{\zlabel{#1}\label{#1}}

\endinput
_______________________________________________
auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex

Reply via email to