> Hi Uwe,
   > Uwe Brauer <[email protected]> writes:

   > I'm not sure if I understand this correctly, but I see a point here:
   > `TeX-arg-ref' inserts an empty pair of braces when the argument is
   > empty.


   > It is `LaTeX-label' (ah! ;-) which behaves almost exactly as
   > `reftex-label'.  You could write a function like this:

   >     (defun LaTeX-exam-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) type)))

   > And then:

   >    (TeX-add-symbols
   >     '("titledquestion" "Title" ["Points"] LaTeX-exam-label 
(TeX-arg-literal " "))


Thanks very much I almost finished to add all the macros, when I run
into the problem, so you are almost re conquering the crown again. I say
almost because:

   > Note that with RefTeX enabled, the job is transferred to `reftex-label',
   > otherwise `LaTeX-label' itself does it.

   > Here a small file I tested with:

   > \documentclass{exam}

   > \qformat{Question \thequestion: \thequestiontitle\dotfill\thepoints}

   > \begin{document}

   > \begin{questions}
   > \titledquestion{RefTeX is not plugged into AUCTeX}[0] When asked for a
   >   \verb|(Optional:) What label|, just hit \verb|RET| and nothing is
   >   inserted
   > \titledquestion{RefTeX is not plugged into AUCTeX}[0]\label{one} When
   >   asked for a \verb|(Optional:) What label|, enter \verb|<key>| and
   >   \verb|\label{<key>}| is inserted
   > %
   > \titledquestion{RefTeX is plugged into AUCTeX}[100] When asked for a
   >   \verb|Label: sec:|, just hit \verb|RET| and nothing is inserted
   > \titledquestion{RefTeX is plugged into AUCTeX}[100]\label{sec:reftex}
   >   When asked for a \verb|Label: sec:|, enter \verb|<label>| and
   >   \verb|\label{<sec:label>}| is inserted
   > \end{questions}

The problem is with the behavior of the last case.

IMHO, when RefTeX is plugged in, the label should be inserted
*automatically* without any prompt. That is the value of the label is
automatically calculated by RefTeX. That, at least for me, is the whole
point of RefTeX: one has not to bother and to keep track manually of the
labels used (like oops is it label number 123 or 124, don't remember
right now). [1]



That is why I proposed


(defvar exam-use-reftex nil
  "Variable which controls whether to use `reftex-label' or `TeX-arg-ref'. 
Default is to use `TeX-arg-literal'.")
; or Tex-exam-label


(if exam-use-reftex
    (defalias 'TeX-arg-literal 'reftex-label))

   > \end{document}

   > Best, Arash


Footnotes: 
[1]  frankly, without starting a flamewar, assigning labels in AUCTeX
     without RefTex is for my like using plain tex instead of LaTeX.


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

Reply via email to