From edd282ae7711673ebc90fd401412d7f39f4908b8 Mon Sep 17 00:00:00 2001 From: Shawn Jones Date: Tue, 6 Aug 2024 20:07:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BA=86org=E5=AF=BC?= =?UTF-8?q?=E5=87=BApdf=EF=BC=8C=E9=80=82=E9=85=8D=E4=B8=AD=E6=96=87=20pro?= =?UTF-8?q?jectile=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=B7=BB=E5=8A=A0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lisp/init-org.el | 279 ++++++++++++++++------------------------ lisp/init-projectile.el | 3 +- 2 files changed, 115 insertions(+), 167 deletions(-) diff --git a/lisp/init-org.el b/lisp/init-org.el index 594cbc8..d26def2 100644 --- a/lisp/init-org.el +++ b/lisp/init-org.el @@ -1,208 +1,155 @@ -;;; init-org.el -- org配置 +;;; init-org.el -- Org mode 配置 ;;; Commentary: +;;; 配置 Org mode 以适应 LaTeX 导出、Org Babel 语言支持以及其他功能。 ;;; Code: -(add-hook 'org-mode-hook -(lambda () (setq truncate-lines nil))) -(require 'ox-latex) -;; 使用xelatex一步生成PDF -(setq org-latex-pdf-process - '("xelatex -interaction nonstopmode -output-directory %o %f" - "xelatex -interaction nonstopmode -output-directory %o %f" - "xelatex -interaction nonstopmode -output-directory %o %f")) -;; code执行免应答(Eval code without confirm) -(setq org-confirm-babel-evaluate nil) -;; Auctex -(setq TeX-auto-save t) -(setq TeX-parse-self t) -(setq-default TeX-master nil) -(defun org-mode-article-modes () - (reftex-mode t) - (and (buffer-file-name) - (file-exists-p (buffer-file-name)) - (reftex-parse-all))) +;; 启用 Org mode 钩子并设置必要的参数 (add-hook 'org-mode-hook (lambda () - (if (member "REFTEX" org-todo-keywords-1) - (org-mode-article-modes)))) -(unless (boundp 'org-export-latex-classes) - (setq org-export-latex-classes nil)) + (setq truncate-lines nil) ;; 不截断长行 + (when (member "REFTEX" org-todo-keywords-1) + (reftex-mode t) ;; 启用 RefTeX 模式 + (and (buffer-file-name) + (file-exists-p (buffer-file-name)) + (reftex-parse-all))))) -;; 导出路径设置 -(defun my-org-export-directory () - "Set the export directory based on the operating system." - (if (eq system-type 'windows-nt) - "C:/workspace/org-export" - "~/org-export")) -(setq org-export-directory (my-org-export-directory)) +;; 使用 ox-latex 包进行 LaTeX 导出 +(require 'ox-latex) +;; 配置 LaTeX 导出使用 xelatex 和 minted 代码高亮 +(setq org-latex-listings 'minted + org-latex-packages-alist '(("" "minted")) + org-latex-pdf-process + '("xelatex -8bit -shell-escape -interaction nonstopmode -output-directory %o %f" + "xelatex -8bit -shell-escape -interaction nonstopmode -output-directory %o %f" + "xelatex -8bit -shell-escape -interaction nonstopmode -output-directory %o %f")) -;; latex-classes 配置 -(setq org-latex-classes nil) ;; 初始化变量,以防止冲突 +;; 配置 LaTeX 导出的超链接颜色和其他属性 +(setq org-latex-hyperref-template nil) ;; 禁用默认的 hyperref 设置 +(setq org-latex-with-hyperref t) ;; 启用 hyperref +(setq org-latex-packages-alist '(("colorlinks=true,linkcolor=blue,urlcolor=cyan" "hyperref" nil))) + +;; 设置 AUCTeX 自动保存与解析 +(setq TeX-auto-save t + TeX-parse-self t + TeX-master nil) + +;; 禁用 Babel 代码执行确认提示 +(setq org-confirm-babel-evaluate nil) + +;; 自定义 LaTeX 类 +(setq org-latex-classes nil) ;; 初始化变量以防止冲突 (add-to-list 'org-latex-classes '("cn-article" "\\documentclass[10pt,a4paper]{article} -\\usepackage{graphicx} -\\usepackage{xcolor} -\\usepackage{xeCJK} -\\usepackage{lmodern} -\\usepackage{verbatim} -\\usepackage{fixltx2e} -\\usepackage{longtable} -\\usepackage{float} -\\usepackage{tikz} -\\usepackage{wrapfig} -\\usepackage{soul} -\\usepackage{textcomp} -\\usepackage{listings} -\\usepackage{geometry} -\\usepackage{algorithm} -\\usepackage{algorithmic} -\\usepackage{marvosym} -\\usepackage{wasysym} -\\usepackage{latexsym} -\\usepackage{natbib} -\\usepackage{fancyhdr} -\\usepackage[xetex,colorlinks=true,CJKbookmarks=true, -linkcolor=blue, -urlcolor=blue, -menucolor=blue]{hyperref} -\\usepackage{fontspec,xunicode,xltxtra} -\\usepackage{ifplatform} -\\ifwindows - \\setmainfont{Consolas} - \\setsansfont{Consolas} - \\setmonofont{Consolas} -\\else - \\setmainfont{Ubuntu Mono} - \\setsansfont{Ubuntu Mono} - \\setmonofont{Ubuntu Mono} -\\fi -\\setCJKmainfont[BoldFont=SimHei]{SimSun} % 设置仿宋字体 -\\setCJKmonofont{SimSun} % 设置仿宋字体为等宽字体 -\\hypersetup{unicode=true} -\\geometry{a4paper, textwidth=6.5in, textheight=10in, -marginparsep=7pt, marginparwidth=.6in} -\\definecolor{foreground}{RGB}{220,220,204}%浅灰 -\\definecolor{background}{RGB}{62,62,62}%浅黑 -\\definecolor{preprocess}{RGB}{250,187,249}%浅紫 -\\definecolor{var}{RGB}{239,224,174}%浅肉色 -\\definecolor{string}{RGB}{154,150,230}%浅紫色 -\\definecolor{type}{RGB}{225,225,116}%浅黄 -\\definecolor{function}{RGB}{140,206,211}%浅天蓝 -\\definecolor{keyword}{RGB}{239,224,174}%浅肉色 -\\definecolor{comment}{RGB}{180,98,4}%深褐色 -\\definecolor{doc}{RGB}{175,215,175}%浅铅绿 -\\definecolor{comdil}{RGB}{111,128,111}%深灰 -\\definecolor{constant}{RGB}{220,162,170}%粉红 -\\definecolor{buildin}{RGB}{127,159,127}%深铅绿 -\\punctstyle{kaiming} -\\title{} -\\fancyfoot[C]{\\bfseries\\thepage} -\\chead{\\MakeUppercase\\sectionmark} -\\pagestyle{fancy} -\\tolerance=1000 +\\usepackage{fontspec} % 引入 fontspec 包 +\\usepackage{xeCJK} % 引入 xeCJK 包处理中文 +% 设置英文字体 +\\setmainfont{Consolas} +\\setsansfont{Arial} +\\setmonofont{Consolas} % 设置等宽字体,用于代码 +% 设置中文字体 +\\setCJKmainfont{SimSun} % 设置中文主字体为宋体 +\\setCJKsansfont{SimHei} % 设置中文无衬线字体为黑体 +\\setCJKmonofont{FangSong} % 设置中文等宽字体为仿宋 +% 设置段落和行距 +\\setlength{\parindent}{2em} % 首行缩进 +\\setlength{\parskip}{0.5em} % 段落间距 +\\linespread{1.5} % 行间距 +\\usepackage[cache=false]{minted} [NO-DEFAULT-PACKAGES] [NO-PACKAGES]" -("\\section{%s}" . "\\section*{%s}") -("\\subsection{%s}" . "\\subsection*{%s}") -("\\subsubsection{%s}" . "\\subsubsection*{%s}") -("\\paragraph{%s}" . "\\paragraph*{%s}") -("\\subparagraph{%s}" . "\\subparagraph*{%s}"))) + ("\\section{%s}" . "\\section*{%s}") + ("\\subsection{%s}" . "\\subsection*{%s}") + ("\\subsubsection{%s}" . "\\subsubsection*{%s}") + ("\\paragraph{%s}" . "\\paragraph*{%s}") + ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))) -(setq org-export-latex-listings t) -(setq org-export-latex-listings-options - '( - ("basicstyle" "\\color{foreground}\\small\\ttfamily") ; 源代码字体样式 - ("keywordstyle" "\\color{function}\\bfseries\\small\\ttfamily") ; 关键词字体样式 - ("identifierstyle" "\\color{doc}\\small\\ttfamily") - ("commentstyle" "\\color{comment}\\small\\itshape") ; 批注样式 - ("stringstyle" "\\color{string}\\small") ; 字符串样式 - ("showstringspaces" "false") ; 字符串空格显示 - ("numbers" "left") ; 行号显示 - ("numberstyle" "\\color{preprocess}") ; 行号样式 - ("stepnumber" "1") ; 行号递增 - ("backgroundcolor" "\\color{background}") ; 代码框背景色 - ("tabsize" "4") ; TAB等效空格数 - ("captionpos" "t") ; 标题位置 top or bottom(t|b) - ("breaklines" "true") ; 自动断行 - ("breakatwhitespace" "true") ; 只在空格分行 - ("showspaces" "false") ; 显示空格 - ("columns" "flexible") ; 列样式 - ("frame" "single") ; 代码框:阴影盒 - ("frameround" "tttt") ; 代码框:圆角 - ("framesep" "0pt") - ("framerule" "8pt") - ("rulecolor" "\\color{background}") - ("fillcolor" "\\color{white}") - ("rulesepcolor" "\\color{comdil}") - ("framexleftmargin" "10mm") +;; 配置 LaTeX 导出的 minted 代码框选项 +(setq org-export-latex-minted-options + '(("frame" "single") ;; 代码框:阴影盒 + ("frameround" "tttt") ;; 代码框:圆角 + ("fontsize" "\\scriptsize") ;; 代码框字体大小 + ("linenos" "true") ;; 显示行号 + ("breaklines" "true") ;; 自动换行 + ("numbersep" "5pt") ;; 行号与代码距离 + ("xleftmargin" "1em") ;; 左边距 + ("xrightmargin" "1em") ;; 右边距 + ("bgcolor" "lightgray") ;; 背景颜色 + ("escapeinside" "||") ;; 特殊字符 )) -;; 在导出 LaTeX 文档时插入字体设置代码 -(setq org-latex-packages-alist - '(("AUTO" "ifplatform" t) - ("AUTO" "fontspec" t) - ("AUTO" "xunicode" t) - ("AUTO" "xltxtra" t) - ;; 以下代码插入字体设置部分 - ("" "\\ifwindows - \\setmonofont{Consolas} -\\else - \\setmonofont{Ubuntu Mono} -\\fi" t))) +;; 导出前移除 hypersetup 设置,以免显示在文档中 +(defun my/org-latex-remove-hypersetup (backend) + "Remove hypersetup settings in the exported LaTeX file." + (goto-char (point-min)) + (while (re-search-forward "hypersetup.*" nil t) + (replace-match ""))) -;; 使用 ido 完成 Org Mode 的提示 -(setq org-completion-use-ido t) -;; 启用 Org Babel 对多种编程语言的支持 +(add-hook 'org-export-before-processing-hook 'my/org-latex-remove-hypersetup) +;; 配置 Org Babel 支持多种编程语言 (org-babel-do-load-languages 'org-babel-load-languages - '((R . t) ; 支持 R 语言 - (emacs-lisp . t) ; 支持 Emacs Lisp - (matlab . t) ; 支持 Matlab - (C . t) ; 支持 C 语言 - (perl . t) ; 支持 Perl - (shell . t) ; 支持 Shell 脚本 - (ditaa . t) ; 支持 ditaa 图形 - (python . t) ; 支持 Python - (haskell . t) ; 支持 Haskell - (dot . t) ; 支持 Graphviz dot 语言 - (latex . t) ; 支持 LaTeX - (js . t) ; 支持 JavaScript + '((R . t) ;; 支持 R 语言 + (emacs-lisp . t) ;; 支持 Emacs Lisp + (java . t) ;; 支持 Java + (matlab . t) ;; 支持 Matlab + (C . t) ;; 支持 C 语言 + (perl . t) ;; 支持 Perl + (shell . t) ;; 支持 Shell 脚本 + (ditaa . t) ;; 支持 ditaa 图形 + (python . t) ;; 支持 Python + (haskell . t) ;; 支持 Haskell + (dot . t) ;; 支持 Graphviz dot 语言 + (latex . t) ;; 支持 LaTeX + (js . t) ;; 支持 JavaScript )) -;;; org-roam org-mode笔记管理 +;;; Org-roam 配置,用于 Org mode 笔记管理 (use-package org-roam :ensure t :custom - (org-roam-directory (file-truename (concat (getenv "USERPROFILE") "\\OneDrive\\文档\\org笔记"))) - (org-roam-db-location (concat (getenv "USERPROFILE") "\\OneDrive\\文档\\org笔记\\org-roam.db")) + (org-roam-directory "C:/workspace/documents") + (org-roam-db-location "C:/workspace/documents/org-roam.db") :config + (setq org-roam-capture-templates + '(("d" "default" plain + "%?" + :if-new (file+head "${slug}.org" + "#+title: ${title}\n") + :unnarrowed t))) (setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag))) (org-roam-db-autosync-mode) - (require 'org-roam-protocol) - ) + (require 'org-roam-protocol)) -;; 打印选项 +;; 在创建 org-mode buffer, 自动添加 latex class 解决生成中文pdf 问题 +(eval-after-load 'autoinsert + '(define-auto-insert '(org-mode . "Chinese Org skeleton") + '("Description: " + "#+LATEX_CLASS: cn-article\n" + "#+LATEX_CLASS_OPTIONS: [oneside,A4paper,12pt]\n"))) +(auto-insert-mode) +(setq auto-insert-query nil) + +;; 设置打印选项 (setq ps-paper-type 'a4 ps-font-size 16.0 - ps-print-header nil ; 不打印页眉 - ps-landscape-mode nil ;纵向 - ) + ps-print-header nil + ps-landscape-mode nil) -;; 取org-mode中C-,快捷键的绑定 +;; 解除 org-mode 中 C-, 快捷键的绑定 (add-hook 'org-mode-hook (lambda () - (local-unset-key (kbd "C-,")) - )) + (local-unset-key (kbd "C-,")))) +;; Org mode 操作的 Hydras 配置 (defhydra hydra-org-operations (:color blue :hint nil) " ^节点^ ^^^^^^^^^----------- _f_: 查找节点 " - ("f" org-roam-node-find "查找节点") - ) + ("f" org-roam-node-find "查找节点")) +;; 提供 init-org 模块 (provide 'init-org) ;;; init-org.el ends here diff --git a/lisp/init-projectile.el b/lisp/init-projectile.el index 22782f2..d404a46 100644 --- a/lisp/init-projectile.el +++ b/lisp/init-projectile.el @@ -17,7 +17,7 @@ _p_: 切换项目 _f_: 查找文件 _d_: 查找目录 _s_: 正则查找 _g_: 全局搜索 _b_: 切换缓冲区 -_r_: 重命名项目 ^ ^ +_r_: 重命名项目 _a_: 添加项目 " ("p" projectile-switch-project "切换项目") ("f" projectile-find-file "查找文件") @@ -26,6 +26,7 @@ _r_: 重命名项目 ^ ^ ("g" projectile-grep "全局搜索") ("b" projectile-switch-to-buffer "切换缓冲区") ("r" projectile-replace "重命名项目") + ("a" projectile-add-known-project "添加项目") ) (provide 'init-projectile)