fix(org-latex): use :around advice on org-latex-table instead of filter
org-export-filter-table-functions timing was unreliable (after! ox-latex runs too late or filter not called for all table types). Around advice on org-latex-table is called directly during transcoding, guaranteed to run. Also switched to with-eval-after-load for more predictable load timing.
This commit is contained in:
37
config.el
37
config.el
@@ -326,25 +326,26 @@ Bound to cmd+v in org-mode and markdown-mode."
|
|||||||
;;; ============================================================
|
;;; ============================================================
|
||||||
|
|
||||||
;; LaTeX table export: replace tabular → tabularx{\textwidth}
|
;; LaTeX table export: replace tabular → tabularx{\textwidth}
|
||||||
;; Filter approach: works on rendered LaTeX string, never touches the org buffer,
|
;; Around advice on org-latex-table (more reliable than filter hooks).
|
||||||
;; so no hook recursion (the old before-processing-hook + insert approach caused
|
;; No buffer modification → no recursion risk.
|
||||||
;; 'max-lisp-eval-depth' via org-element-cache after-change hooks).
|
(defun my/org-latex-table-tabularx (orig-fn table contents info)
|
||||||
(defun my/org-latex-table-to-tabularx (table _backend _info)
|
"Wrap org-latex-table output: replace tabular with tabularx{\\textwidth}."
|
||||||
"Replace \\begin{tabular} with \\begin{tabularx}{\\textwidth} in LaTeX output."
|
(let ((result (funcall orig-fn table contents info)))
|
||||||
(when (and (stringp table) (string-match "\\\\begin{tabular}" table))
|
(when (stringp result)
|
||||||
(setq table (replace-regexp-in-string
|
(setq result
|
||||||
"\\\\begin{tabular}{\\([^}]*\\)}"
|
(replace-regexp-in-string
|
||||||
"\\\\begin{tabularx}{\\\\textwidth}{\\1}"
|
"\\\\begin{tabular}{\\([^}]*\\)}"
|
||||||
table))
|
"\\\\begin{tabularx}{\\\\textwidth}{\\1}"
|
||||||
(setq table (replace-regexp-in-string
|
result))
|
||||||
"\\\\end{tabular}"
|
(setq result
|
||||||
"\\\\end{tabularx}"
|
(replace-regexp-in-string
|
||||||
table)))
|
"\\\\end{tabular}"
|
||||||
table)
|
"\\\\end{tabularx}"
|
||||||
|
result)))
|
||||||
|
result))
|
||||||
|
|
||||||
(after! ox-latex
|
(with-eval-after-load 'ox-latex
|
||||||
(add-to-list 'org-export-filter-table-functions
|
(advice-add 'org-latex-table :around #'my/org-latex-table-tabularx)
|
||||||
#'my/org-latex-table-to-tabularx)
|
|
||||||
(add-to-list 'org-latex-packages-alist '("" "tabularx")))
|
(add-to-list 'org-latex-packages-alist '("" "tabularx")))
|
||||||
|
|
||||||
;; Optional: enable booktabs style (horizontal rules in tables)
|
;; Optional: enable booktabs style (horizontal rules in tables)
|
||||||
|
|||||||
Reference in New Issue
Block a user