[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: TeX-command-run-all (C-c C-a) doesn't run to generate Table of Conte
From: |
Arash Esbati |
Subject: |
Re: TeX-command-run-all (C-c C-a) doesn't run to generate Table of Contents |
Date: |
Fri, 21 Jan 2022 09:51:04 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 |
Hi Pieter,
Pieter van Oostrum <pieter-l@vanoostrum.org> writes:
> However, for a new document containing '\tableofcontents', the
> document isn't finished unless another LaTeX run is done that puts the
> ToC in the document. Is there a way for AUCTeX to detect this need? I
> am using version 13.0.16 of AUCTeX which doesn't do that.
>
> I know there isn't a warning in the .log file about this, but it does say:
> No file <document>.toc.
> Together with the presence of the `\tableofcontents` command this
> could give an indication that an additional run may be necessary. The
> same for 'lot' and 'lof'.
Thanks for raising this issue. Indeed, there is no entry for this in
the function `TeX-LaTeX-sentinel'. The entry could look like this:
((re-search-forward "^No file .*\\.\\(toc\\|lof\\|lot\\)\\.$" nil t)
(message "%s" (concat "You should run LaTeX again to get "
(upcase (match-string-no-properties 1))
" right"))
(setq TeX-command-next TeX-command-default))
I'm attaching the complete (longish) function below. Can you give it a
try? Ideally, you hit C-c C-a once so that tex-buf.el is loaded, then
eval my version, enter \tableofcontents in your .tex file and hit C-c
C-a again.
> And yes, I know that the problem can be solved by using LatexMk.
C'mon 😉
--8<---------------cut here---------------start------------->8---
(defun TeX-LaTeX-sentinel (process name)
"Cleanup TeX output buffer after running LaTeX.
Parse the output buffer to collect errors and warnings if the
variable `TeX-parse-all-errors' is non-nil.
Open the error overview if
`TeX-error-overview-open-after-TeX-run' is non-nil and there are
errors or warnings to show."
(if TeX-parse-all-errors
(TeX-parse-all-errors))
(if (and TeX-error-overview-open-after-TeX-run
(TeX-error-overview-make-entries
(TeX-master-directory) (TeX-active-buffer)))
(TeX-error-overview))
(cond ((TeX-TeX-sentinel-check process name))
((and (save-excursion
(re-search-forward
"^Package biblatex Warning: Please (re)run Biber on the file"
nil t))
(with-current-buffer TeX-command-buffer
(and (LaTeX-bibliography-list)
(TeX-check-files (TeX-master-file "bbl")
(TeX-style-list)
(append TeX-file-extensions
BibTeX-file-extensions
TeX-Biber-file-extensions)))))
(message "%s%s" "You should run Biber to get citations right, "
(TeX-current-pages))
(setq TeX-command-next (with-current-buffer TeX-command-buffer
TeX-command-Biber)))
((and (save-excursion
(re-search-forward
"^\\(?:LaTeX\\|Package natbib\\) Warning: Citation" nil t))
(with-current-buffer TeX-command-buffer
(and (LaTeX-bibliography-list)
(TeX-check-files (TeX-master-file "bbl")
(TeX-style-list)
(append TeX-file-extensions
BibTeX-file-extensions
TeX-Biber-file-extensions)))))
(message "%s%s" "You should run BibTeX to get citations right, "
(TeX-current-pages))
(setq TeX-command-next (with-current-buffer TeX-command-buffer
TeX-command-BibTeX)))
((re-search-forward "Package biblatex Warning: Please rerun LaTeX" nil
t)
(message "%s%s" "You should run LaTeX again, " (TeX-current-pages))
(setq TeX-command-next TeX-command-default))
((re-search-forward "^(biblatex)\\W+Page breaks have changed" nil t)
(message "%s%s" "You should run LaTeX again - page breaks have
changed, "
(TeX-current-pages))
(setq TeX-command-next TeX-command-default))
((re-search-forward "^\\(?:LaTeX Warning: Label(s)\\|\
Package natbib Warning: Citation(s)\\)" nil t)
(message "%s%s" "You should run LaTeX again to get references right, "
(TeX-current-pages))
(setq TeX-command-next TeX-command-default))
((re-search-forward
"^\\(?:(rerunfilecheck)\\|Package hyperref Warning:\\)\\W+\
Rerun to get outlines right" nil t)
(message "%s%s" "You should run LaTeX again to get outlines right, "
(TeX-current-pages))
(setq TeX-command-next TeX-command-default))
((re-search-forward "^LaTeX Warning: Reference" nil t)
(message "%s%s%s" name ": there were unresolved references, "
(TeX-current-pages))
(let (dvi2pdf)
(if (with-current-buffer TeX-command-buffer
(and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
(setq TeX-command-next dvi2pdf)
(setq TeX-command-next TeX-command-Show))))
((re-search-forward "^\\(?:LaTeX Warning: Citation\\|\
Package natbib Warning:.*undefined citations\\)" nil t)
(message "%s%s%s" name ": there were unresolved citations, "
(TeX-current-pages))
(let (dvi2pdf)
(if (with-current-buffer TeX-command-buffer
(and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
(setq TeX-command-next dvi2pdf)
(setq TeX-command-next TeX-command-Show))))
((re-search-forward "Package longtable Warning: Table widths have \
changed\\. Rerun LaTeX\\." nil t)
(message
"%s" "You should run LaTeX again to get table formatting right")
(setq TeX-command-next TeX-command-default))
((re-search-forward "^hf-TikZ Warning: Mark '.*' changed\\. \
Rerun to get mark in right position\\." nil t)
(message
"%s" "You should run LaTeX again to get TikZ marks in right position")
(setq TeX-command-next TeX-command-default))
((re-search-forward "^\\* xsim warning: \"rerun\"" nil t)
(message
"%s" "You should run LaTeX again to synchronize exercise properties")
(setq TeX-command-next TeX-command-default))
((re-search-forward "^No file .*\\.\\(toc\\|lof\\|lot\\)\\.$" nil t)
(message "%s" (concat "You should run LaTeX again to get "
(upcase (match-string-no-properties 1))
" right"))
(setq TeX-command-next TeX-command-default))
((re-search-forward
"^\\(\\*\\* \\)?J?I?p?\\(La\\|Sli\\)TeX\\(2e\\)? \
\\(Version\\|ver\\.\\|<[0-9/-]*\\(?:u[^>]*\\)?>\\)" nil t)
(let* ((warnings (and TeX-debug-warnings
(TeX-LaTeX-sentinel-has-warnings)))
(bad-boxes (and TeX-debug-bad-boxes
(TeX-LaTeX-sentinel-has-bad-boxes)))
(add-info (when (or warnings bad-boxes)
(concat " (with "
(when warnings "warnings")
(when (and warnings bad-boxes) " and ")
(when bad-boxes "bad boxes")
")"))))
(message "%s" (concat name ": successfully formatted "
(TeX-current-pages) add-info)))
(let (dvi2pdf)
(if (with-current-buffer TeX-command-buffer
(and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
(setq TeX-command-next dvi2pdf)
(setq TeX-command-next TeX-command-Show))))
(t
(message "%s%s%s" name ": problems after " (TeX-current-pages))
(setq TeX-command-next TeX-command-default)))
;; Check whether the idx file changed.
(let (idx-file)
(and (file-exists-p
(setq idx-file
(with-current-buffer TeX-command-buffer
(expand-file-name (TeX-active-master "idx")))))
;; imakeidx package automatically runs makeindex, thus, we need to be
;; sure .ind file isn't newer than .idx.
(TeX-check-files (with-current-buffer TeX-command-buffer
(expand-file-name (TeX-active-master "ind")))
(with-current-buffer TeX-command-buffer
(list (file-name-nondirectory (TeX-active-master))))
'("idx"))
(with-temp-buffer
(insert-file-contents-literally idx-file)
(not (equal
;; Compare old md5 hash of the idx file with the new one.
(cdr (assoc idx-file LaTeX-idx-md5-alist))
(md5 (current-buffer)))))
(push (cons idx-file t) LaTeX-idx-changed-alist)))
(unless (TeX-error-report-has-errors-p)
(run-hook-with-args 'TeX-after-compilation-finished-functions
(with-current-buffer TeX-command-buffer
(expand-file-name
(TeX-active-master (TeX-output-extension)))))))
--8<---------------cut here---------------end--------------->8---
Best, Arash