feat(pdf+org-latex): pdf-tools config + fix tabularx via default-table-environment
org-latex tabularx:
- Dropped advice/filter/hook approaches (all caused issues)
- Use org-latex-default-table-environment="tabularx" — org natively
handles tabularx/tabulary by inserting \linewidth width arg automatically
- tabularx added to org-latex-packages-alist
pdf-tools:
- pdf-tools-install :no-query (auto-builds server binary)
- pdf-view: fit-page default, Retina scaling, midnight dark theme,
continuous scrolling, auto-revert after LaTeX re-export, no line numbers
- Evil keybinds: j/k scroll, J/K pages, gg/G first/last, +/-/= zoom,
W fit-width, / search, m midnight toggle, a annotate, q quit
- org-file-apps on macOS: PDF opens in Emacs (pdf-view-mode via auto-mode)
instead of system Preview
This commit is contained in:
91
config.el
91
config.el
@@ -325,42 +325,17 @@ Bound to cmd+v in org-mode and markdown-mode."
|
||||
;;; ORG MODE — LATEX EXPORT
|
||||
;;; ============================================================
|
||||
|
||||
;; LaTeX table export: replace tabular → tabularx{\textwidth}
|
||||
;; Around advice on org-latex-table (more reliable than filter hooks).
|
||||
;; No buffer modification → no recursion risk.
|
||||
(defun my/org-latex-table-tabularx (orig-fn table contents info)
|
||||
"Wrap org-latex-table output: replace tabular with tabularx{\\textwidth}."
|
||||
(let ((result (funcall orig-fn table contents info)))
|
||||
(when (stringp result)
|
||||
(setq result
|
||||
(replace-regexp-in-string
|
||||
"\\\\begin{tabular}{\\([^}]*\\)}"
|
||||
"\\\\begin{tabularx}{\\\\textwidth}{\\1}"
|
||||
result))
|
||||
(setq result
|
||||
(replace-regexp-in-string
|
||||
"\\\\end{tabular}"
|
||||
"\\\\end{tabularx}"
|
||||
result)))
|
||||
result))
|
||||
|
||||
(with-eval-after-load 'ox-latex
|
||||
(advice-add 'org-latex-table :around #'my/org-latex-table-tabularx)
|
||||
;; LaTeX table export: use tabularx as default environment.
|
||||
;; Org natively supports tabularx: when environment is "tabularx" or "tabulary",
|
||||
;; it automatically inserts the required width argument (\linewidth).
|
||||
;; No buffer modification, no advice, no filter needed.
|
||||
(after! ox-latex
|
||||
(setq org-latex-default-table-environment "tabularx")
|
||||
(add-to-list 'org-latex-packages-alist '("" "tabularx")))
|
||||
|
||||
;; Optional: enable booktabs style (horizontal rules in tables)
|
||||
;; (setq org-latex-tables-booktabs t)
|
||||
|
||||
;; macOS: open exported PDF with system 'open' (async → no beachball)
|
||||
;; Without this, org-open-file may call open synchronously or fail silently.
|
||||
(when (eq system-type 'darwin)
|
||||
(setq org-file-apps
|
||||
'((auto-mode . emacs)
|
||||
(directory . emacs)
|
||||
("\\.mm\\'" . default)
|
||||
("\\.x?html?\\'" . default)
|
||||
("\\.pdf\\'" . "open %s"))))
|
||||
|
||||
;; Ensure latexmk doesn't hang on errors (nonstopmode + force-continue)
|
||||
;; Doom latex module usually sets this, but belt+suspenders for macOS.
|
||||
(after! org
|
||||
@@ -1028,3 +1003,57 @@ Otherwise: runs interactive ement-connect, then opens rooms after sync."
|
||||
:desc "Join room" "j" #'ement-join-room
|
||||
:desc "Notifications" "n" #'ement-notifications
|
||||
:desc "Mentions" "m" #'ement-mentions))
|
||||
|
||||
|
||||
;;; ============================================================
|
||||
;;; PDF TOOLS
|
||||
;;; ============================================================
|
||||
|
||||
;; pdf-tools: install server binary on first load
|
||||
(after! pdf-tools
|
||||
(pdf-tools-install :no-query))
|
||||
|
||||
;; pdf-view-mode settings
|
||||
(after! pdf-view
|
||||
;; Fit page to window width by default
|
||||
(setq-default pdf-view-display-size 'fit-page)
|
||||
;; High-res rendering on Retina displays
|
||||
(setq pdf-view-use-scaling t
|
||||
pdf-view-use-imagemagick nil)
|
||||
;; Midnight mode (dark background) — toggle with M-m or keybind
|
||||
(setq pdf-view-midnight-colors '("#d4d4d4" . "#1c1c1c"))
|
||||
;; Continuous scrolling across pages
|
||||
(setq pdf-view-continuous t)
|
||||
;; No line-number gutter
|
||||
(add-hook 'pdf-view-mode-hook #'(lambda ()
|
||||
(display-line-numbers-mode -1)))
|
||||
;; Auto-revert when PDF is regenerated (e.g. after org LaTeX export)
|
||||
(add-hook 'pdf-view-mode-hook #'auto-revert-mode))
|
||||
|
||||
;; Evil-friendly keybinds in pdf-view
|
||||
(after! pdf-view
|
||||
(evil-define-key 'normal pdf-view-mode-map
|
||||
"j" #'pdf-view-next-line-or-next-page
|
||||
"k" #'pdf-view-previous-line-or-previous-page
|
||||
"J" #'pdf-view-next-page
|
||||
"K" #'pdf-view-previous-page
|
||||
"gg" #'pdf-view-first-page
|
||||
"G" #'pdf-view-last-page
|
||||
"+" #'pdf-view-enlarge
|
||||
"-" #'pdf-view-shrink
|
||||
"=" #'pdf-view-fit-page-to-window
|
||||
"W" #'pdf-view-fit-width-to-window
|
||||
"/" #'isearch-forward
|
||||
"?" #'isearch-backward
|
||||
"m" #'pdf-view-midnight-minor-mode
|
||||
"a" #'pdf-annot-add-highlight-markup-annotation
|
||||
"q" #'quit-window))
|
||||
|
||||
;; Open PDFs from org export in Emacs (pdf-view-mode) instead of Preview
|
||||
(when (eq system-type 'darwin)
|
||||
(setq org-file-apps
|
||||
'((auto-mode . emacs)
|
||||
(directory . emacs)
|
||||
("\\.mm\\'" . default)
|
||||
("\\.x?html?\\'" . default)
|
||||
("\\.pdf\\'" . emacs)))) ; find-file → pdf-view-mode via auto-mode-alist
|
||||
|
||||
Reference in New Issue
Block a user