Re: [AUCTeX-devel] insert a label with the file name as suffix.
Uwe Brauer writes: > Ok that error I resolved (on my Ubuntu machine there is still a emacs 24 > installed) > > So I tried out emacs 25 (and 26) -Q or -q > > And loaded the following file > , > | > | (setq load-path (cons (expand-file-name > "~/emacs/site-lisp/packages/auctex-git") load-path)) > | (setq load-path (cons (expand-file-name > "~/emacs/site-lisp/packages/auctex-git/auctex") load-path)) > | > | (load "auctex.el" nil t t) > | (load "preview-latex.el" nil t t) > | > | (require 'tex-site) > | > | (require 'reftex) > | > | (with-eval-after-load "latex" > | (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label))) > | > | (with-eval-after-load "tex-style" > | (add-to-list 'reftex-label-alist > |`("titledquestion" ?x > | ,(concat LaTeX-exam-label "%f:") > | "~\\ref{%s}" nil ("ejercicio") ))) > ` > > Then I open a exam file such as you said, when running > -c C-m titledquestion RET Title RET 10 RET' > I am *asked* for a label, *but* > \titledquestion{Title}[10]\label{exm:1} Hmm, sorry, no idea. If you're *asked* for label, you could check the value of `reftex-insert-label-flags', but that's not the issue. Best, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
>>> "Uwe" == Uwe Brauer writes: >> Uwe Brauer writes: >> Hmm, I can't reproduce what you describe. I started Emacs, eval'ed the >> above code in scratch buffer, opened test-exam.tex like this: >> \documentclass[answers]{exam} >> \begin{document} >> \begin{questions} >> `C-c C-m titledquestion RET Title RET 10 RET' results in >> \titledquestion{Title}[10]\label{exm:exam-test:1} >> \end{questions} >> \end{document} >> which is the correct result, I think. > It is the correct result, unfortunately I cannot repoduce it. With the > same steps as you indicated I end up with > \titledquestion{Title}[10]\label{exm:1} > So I presume it is my internal setting. > In order to check it > This function is defined in in subr which > Library is file /opt/emacs25/share/emacs/25.1.50/lisp/subr.elc > So I don't understand why it is not loaded while reftex is. Ok that error I resolved (on my Ubuntu machine there is still a emacs 24 installed) So I tried out emacs 25 (and 26) -Q or -q And loaded the following file , | | (setq load-path (cons (expand-file-name "~/emacs/site-lisp/packages/auctex-git") load-path)) | (setq load-path (cons (expand-file-name "~/emacs/site-lisp/packages/auctex-git/auctex") load-path)) | | (load "auctex.el" nil t t) | (load "preview-latex.el" nil t t) | | (require 'tex-site) | | | | (require 'reftex) | | (with-eval-after-load "latex" | (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label))) | | (with-eval-after-load "tex-style" | (add-to-list 'reftex-label-alist |`("titledquestion" ?x | ,(concat LaTeX-exam-label "%f:") | "~\\ref{%s}" nil ("ejercicio") ))) | | | ` Then I open a exam file such as you said, when running -c C-m titledquestion RET Title RET 10 RET' I am *asked* for a label, *but* \titledquestion{Title}[10]\label{exm:1} Is inserted and not the file name. I am puzzled. I will pull again the latest git auctex compile and install it. Uwe ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
> Uwe Brauer writes: > Hmm, I can't reproduce what you describe. I started Emacs, eval'ed the > above code in scratch buffer, opened test-exam.tex like this: > \documentclass[answers]{exam} > \begin{document} > \begin{questions} > `C-c C-m titledquestion RET Title RET 10 RET' results in > \titledquestion{Title}[10]\label{exm:exam-test:1} > \end{questions} > \end{document} > which is the correct result, I think. It is the correct result, unfortunately I cannot repoduce it. With the same steps as you indicated I end up with \titledquestion{Title}[10]\label{exm:1} So I presume it is my internal setting. In order to check it I generated a file my-ref.el which is (require 'reftex) (with-eval-after-load "latex" (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label))) (with-eval-after-load "tex-style" (add-to-list 'reftex-label-alist `("titledquestion" ?x ,(concat LaTeX-exam-label "%f:") "~\\ref{%s}" nil ("ejercicio") ))) Started emacs -Q (or -q) and loaded the file, however I obtained unknown function with-eval-after-load. This function is defined in in subr which Library is file /opt/emacs25/share/emacs/25.1.50/lisp/subr.elc So I don't understand why it is not loaded while reftex is. BTW when I just eval the expression (with-eval-after-load "tex-style" (add-to-list 'reftex-label-alist `("titledquestion" ?x ,(concat LaTeX-exam-label "%f:") "~\\ref{%s}" nil ("ejercicio") ))) And run describe-variable Reftex-label-alist It does not return anything about titledquestion! Should I try to use customize-option? Any suggestion how to proceed? Thanks Uwe ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
Uwe Brauer writes: > > Uwe Brauer writes: > > > Sigh, sorry, my bad. `LaTeX-exam-label' is not defined at that point of > > time. Please try this: > > > (with-eval-after-load "latex" > > (add-to-list 'LaTeX-label-alist '("titledquestion" . > LaTeX-exam-label))) > > > (with-eval-after-load "tex-style" > > (add-to-list 'reftex-label-alist > >`("titledquestion" ?x > > ,(concat LaTeX-exam-label "%f:") > > "~\\ref{%s}" nil ("ejercicio") ))) > > Well thanks, there is no error, but > > It still inserts only > > \titledquestion{Hello}[10]\label{exm:3} > > Instead of > > \titledquestion{Hello}[10]\label{exm:test-exam1:3} Hmm, I can't reproduce what you describe. I started Emacs, eval'ed the above code in scratch buffer, opened test-exam.tex like this: \documentclass[answers]{exam} \begin{document} \begin{questions} `C-c C-m titledquestion RET Title RET 10 RET' results in \titledquestion{Title}[10]\label{exm:exam-test:1} \end{questions} \end{document} which is the correct result, I think. Best, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
> Uwe Brauer writes: > Sigh, sorry, my bad. `LaTeX-exam-label' is not defined at that point of > time. Please try this: > (with-eval-after-load "latex" > (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label))) > (with-eval-after-load "tex-style" > (add-to-list 'reftex-label-alist >`("titledquestion" ?x > ,(concat LaTeX-exam-label "%f:") > "~\\ref{%s}" nil ("ejercicio") ))) Well thanks, there is no error, but It still inserts only \titledquestion{Hello}[10]\label{exm:3} Instead of \titledquestion{Hello}[10]\label{exm:test-exam1:3} Uwe ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
Uwe Brauer writes: > > If you want to put that stuff in your .emacs, try something like this: > > > (with-eval-after-load "latex" > > (add-to-list 'LaTeX-label-alist '("titledquestion" . > LaTeX-exam-label))) > > > (require 'reftex) > > > (add-to-list 'reftex-label-alist > > `("titledquestion" ?x > >,(concat LaTeX-exam-label "%f:") > >"~\\ref{%s}" nil ("ejercicio") )) > > The latter did not work. > > I tried emacs -Q > and loaded the file > > (require 'reftex) > (add-to-list 'reftex-label-alist > `("titledquestion" ?x >,(concat LaTeX-exam-label "%f:") >"~\\ref{%s}" nil ("ejercicio") )) > and obtained > > cons: Symbol's value as variable is void: LaTeX-exam-label Sigh, sorry, my bad. `LaTeX-exam-label' is not defined at that point of time. Please try this: --8<---cut here---start->8--- (with-eval-after-load "latex" (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label))) (with-eval-after-load "tex-style" (add-to-list 'reftex-label-alist `("titledquestion" ?x ,(concat LaTeX-exam-label "%f:") "~\\ref{%s}" nil ("ejercicio") ))) --8<---cut here---end--->8--- Best, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
> Uwe Brauer writes: > Hi Uwe, > I didn't test it, but I'm pretty sure about the syntax ;-) If you look > closer at my code above for RefTeX, you'll see that it uses backquote ` > and not a quote '. See here for why[1]. Ok then I thought that was malformed by the MTA. Thanks for clarifying. > If you want to put that stuff in your .emacs, try something like this: > (with-eval-after-load "latex" > (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label))) > (require 'reftex) > (add-to-list 'reftex-label-alist > `("titledquestion" ?x >,(concat LaTeX-exam-label "%f:") >"~\\ref{%s}" nil ("ejercicio") )) The latter did not work. I tried emacs -Q and loaded the file (require 'reftex) (add-to-list 'reftex-label-alist `("titledquestion" ?x ,(concat LaTeX-exam-label "%f:") "~\\ref{%s}" nil ("ejercicio") )) and obtained cons: Symbol's value as variable is void: LaTeX-exam-label So I did the following (defun my-reftex-label-alist-6 () "Sets reftex-label to have a 6th entry" (interactive) (setq reftex-label-alist '(`("titledquestion" ?x ,(concat LaTeX-exam-label "%f:") "~\\ref{%s}" nil ("ejercicio") (add-hook 'reftex-mode-hook 'my-reftex-label-alist-6) And then run a test in file exam-test.tex When inserting a titledquestion I obtained an error: Debugger entered--Lisp error: (wrong-type-argument characterp ("titledquestion" 120 (\, (concat LaTeX-exam-label "%f:")) "~\\ref{%s}" nil ("ejercicio"))) char-to-string(("titledquestion" 120 (\, (concat LaTeX-exam-label "%f:")) "~\\ref{%s}" nil ("ejercicio"))) reftex-compile-variables() reftex-ensure-compiled-variables() reftex-access-scan-info(nil) reftex-label("questions" nil) LaTeX-label("questions" environment) LaTeX-exam-insert-label(nil) TeX-parse-argument(nil LaTeX-exam-insert-label) TeX-parse-arguments(("Title" ["Points"] LaTeX-exam-insert-label (TeX-arg-literal " "))) TeX-parse-macro("titledquestion" ("Title" ["Points"] LaTeX-exam-insert-label (TeX-arg-literal " "))) TeX-insert-macro("titledquestion") funcall-interactively(TeX-insert-macro "titledquestion") call-interactively(TeX-insert-macro nil nil) command-execute(TeX-insert-macro) ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
Uwe Brauer writes: >> I think the issue is somewhere else: In exam.el, >> `LaTeX-exam-insert-label' is used for "titledquestion" and >> "bonustitledquestion". IIRC, you have to add these environments to >> `LaTeX-label-alist' and `reftex-label-alist' in order to get what you >> want, e.g. > >> (add-to-list 'LaTeX-label-alist '("titledquestion" . > LaTeX-exam-label)) > >> and > >> (add-to-list 'reftex-label-alist >> `("titledquestion" ?x ,LaTeX-exam-label ...)) > > Thanks for your answer. I tried out the following > I set > > (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label)) > > And then I replaced > > (setq reftex-label-alist > '(("titledquestion" ?t "exm:%f:" "~\\ref{%s}" nil ("ejercicio" > > > By > > (setq reftex-label-alist > '(("titledquestion" ?x ,LaTeX-exam-label))) > > Are you sure about that syntax? Now when entering a new latex file I > obtain an error. Hi Uwe, I didn't test it, but I'm pretty sure about the syntax ;-) If you look closer at my code above for RefTeX, you'll see that it uses backquote ` and not a quote '. See here for why[1]. If you want to put that stuff in your .emacs, try something like this: --8<---cut here---start->8--- (with-eval-after-load "latex" (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label))) (require 'reftex) (add-to-list 'reftex-label-alist `("titledquestion" ?x ,(concat LaTeX-exam-label "%f:") "~\\ref{%s}" nil ("ejercicio") )) --8<---cut here---end--->8--- I'm not sure if using ?t is a good idea since it is hard-coded in RefTeX for tables. Best, Arash Footnotes: [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
Hi Arash, > Uwe Brauer writes: > Hi Uwe, > have a look at the defintion of `LaTeX-label': it looks if the variable > `LaTeX-label-function' contains a function and then runs it for label > insertion. I have `(setq reftex-plug-into-AUCTeX t)' in my .emacs and > it gives me: [Snip]... > I think the issue is somewhere else: In exam.el, > `LaTeX-exam-insert-label' is used for "titledquestion" and > "bonustitledquestion". IIRC, you have to add these environments to > `LaTeX-label-alist' and `reftex-label-alist' in order to get what you > want, e.g. > (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label)) > and > (add-to-list 'reftex-label-alist > `("titledquestion" ?x ,LaTeX-exam-label ...)) Thanks for your answer. I tried out the following I set (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label)) And then I replaced (setq reftex-label-alist '( ("titledquestion" ?t "exm:%f:" "~\\ref{%s}" nil ("ejercicio" By (setq reftex-label-alist '(("titledquestion" ?x ,LaTeX-exam-label))) Are you sure about that syntax? Now when entering a new latex file I obtain an error. I will play a bit with your variable suggestion. Debugger entered--Lisp error: (wrong-number-of-arguments setq 21) (setq reftex-label-alist (quote (("equation" 101 "eq:%f:" "~(\\ref{%s})" t ("Equation" "Eq." "Eqn." "Gleichung" "Gl.")) ("neweq" 101 "eq:%f:" "~(\\ref{%s})" t ("Equation" "Eq." "Eqn." "Gleichung" "Gl.")) ("newequation" 101 "eq:%f:" "~(\\ref{%s})" t ("Equation" "Eq." "Eqn." "Gleichung" "Gl.")) ("axiom" 97 "ax:%f:" "~\\ref{%s}" nil ("Axiom" "Ax.")) ("func" 70 "fnc:%f:" "~\\ref{%s}" nil ("funci'on" "Fnc")) ("fact" 67 "fct:%f:" "~\\ref{%s}" nil ("Fact" "Fct")) ("script" 84 "scpt:%f:" "~\\ref{%s}" nil ("Script" "scpt")) ("titledquestion" 120 (\, LaTeX-exam-label ("claim" 107 "clm:%f:" "~\\ref{%s}" t ("Claim" "claim")) ("thm" 104 "thr:%f:" "~\\ref{%s}" t ("Theorem" "Theor." "Th.")) ("example" 69 "ex:%f:" "~\\ref{%s}" t ("Example" "Ejemplo")) ("ex" 65 "ex:%f:" "~\\ref{%s}" t ("Ejercicio" "ejercicio")) ("cor" 99 "cor:%f:" "~\\ref{%s}" t ("Corollary" "Cor." "C.")) ("rem" 82 "rem:%f:" "~\\ref{%s}" t ("Remark" "rem." "R.")) ("SaveListing" 86 "SvL:%f:" "~\\ref{%s}" t ("SaveL") -1) ("prac" 80 "prac:%f:" "~\\ref{%s}" t ("Practica" "prac." "P.")) ("prop" 112 "prop:%f:" "~\\ref{%s}" t ("Proposicion" "proposition" "prop." "P.")) ("sol" 111 "sol:%f:" "~\\ref{%s}" t ("Solucion" "sol." "S.")) ("lstlisting" 71 "lstl:%f:" "~\\ref{%s}" t ("lstlisting" "lst." "L.")) ("lem" 76 "lem:%f:" "~\\ref{%s}" nil ("Lemma" "Lema")) ("slide" 108 "slide:%f:" "~\\ref{%s}" t ("slide")) ("Slide" 83 "slide:%f:" "~\\ref{%s}" t ("slide")) ("prop" 77 "prop:%f:" "~\\ref{%s}" t ("Proposicion" "prop." "P.")) ("\\myfig" 102 "fig:%f:" nil 2) ("defn" 68 "def:%f:" "~\\ref{%s}" nil ("Definition" "Definici'on")) ("enumerate" 105 "item:%f:" "~\\ref{%s}" item (regexp "Items?" "Punkte?")) AMSTeX) my-reftex-label-alist-6() run-hooks(reftex-mode-hook) reftex-mode(t) turn-on-reftex() run-hooks(change-major-mode-after-body-hook text-mode-hook TeX-mode-hook LaTeX-mode-hook) apply(run-hooks (change-major-mode-after-body-hook text-mode-hook TeX-mode-hook LaTeX-mode-hook)) TeX-run-mode-hooks(text-mode-hook TeX-mode-hook LaTeX-mode-hook) TeX-latex-mode() apply(TeX-latex-mode nil) LaTeX-mode() funcall-interactively(LaTeX-mode) call-interactively(LaTeX-mode nil nil) command-execute(LaTeX-mode) > Best, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] insert a label with the file name as suffix.
Uwe Brauer writes: > Now for the exam class, Arash proposed to use > > (defun LaTeX-exam-insert-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) (or type 'environment > > Which does not use anything from reftex. I looked at reftex-label and it > is a bit complicated to say the least. Hi Uwe, have a look at the defintion of `LaTeX-label': it looks if the variable `LaTeX-label-function' contains a function and then runs it for label insertion. I have `(setq reftex-plug-into-AUCTeX t)' in my .emacs and it gives me: ,[ C-h v LaTeX-label-function RET ] | LaTeX-label-function is a variable defined in ‘latex.el’. | Its value is ‘reftex-label’ | Original value was nil | | This variable may be risky if used as a file-local variable. | | Documentation: | *A function inserting a label at point or returning a label string. | [...] ` > So I would appreciate if someone had an idea how to modify > LaTeX-exam-insert-label that is behaves the way I just > described. probably I could hack something up using concat and friends > but I bet there are more elegant solutions. I think the issue is somewhere else: In exam.el, `LaTeX-exam-insert-label' is used for "titledquestion" and "bonustitledquestion". IIRC, you have to add these environments to `LaTeX-label-alist' and `reftex-label-alist' in order to get what you want, e.g. (add-to-list 'LaTeX-label-alist '("titledquestion" . LaTeX-exam-label)) and (add-to-list 'reftex-label-alist `("titledquestion" ?x ,LaTeX-exam-label ...)) Best, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
[AUCTeX-devel] insert a label with the file name as suffix.
Hi currently I am using reftex-label which does precisely what I want, it inserts, after some configuration, a label which consists of the abbreviated environment name, a suffix, reflecting the file name and a number. Example \begin{equation} \label{eq:test:4} \int f dx=0 \end{equation} Now for the exam class, Arash proposed to use (defun LaTeX-exam-insert-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) (or type 'environment Which does not use anything from reftex. I looked at reftex-label and it is a bit complicated to say the least. So I would appreciate if someone had an idea how to modify LaTeX-exam-insert-label that is behaves the way I just described. probably I could hack something up using concat and friends but I bet there are more elegant solutions. Thanks Uwe Brauer ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel