差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
emacs [2023/11/08 00:56] skkemacs [2025/01/13 01:28] (現在) skk
行 1: 行 1:
-= [[emacs]] / LM: [2023-11-08 00:56:36]+= [[emacs]] / LM: [2025-01-13 01:28:49]
 ~~NOCACHE~~ ~~NOCACHE~~
  
行 193: 行 193:
 That is, remove duplicates, non-kept, and excluded files. That is, remove duplicates, non-kept, and excluded files.
 </code> </code>
 +
 +[2023-12-13]
 +
 +recentf が増えてくると,検索したくなる.そのような時は,''M-x recentf-open-files'' と打つと,今までの履歴が一覧で出てきて,''C-s'' などで検索して探しやすくなる.
  
 参考: 参考:
行 667: 行 671:
 これで,Chrome と emacs の間での Window 移動の際に,マウスを使わなくて済むはずである. これで,Chrome と emacs の間での Window 移動の際に,マウスを使わなくて済むはずである.
  
-==== - slack での atomic-chrome [2023-10-15] ====+==== - slack での atomic-chrome ==== 
 +[2023-10-15] 
 ウィンドウの設定を行なうと,atomic-chrome の使い勝手がかなり向上するが,slack で利用することを考えると,emacs 内から submit できるとチャットの効率が大変あがるので便利な気がする. ウィンドウの設定を行なうと,atomic-chrome の使い勝手がかなり向上するが,slack で利用することを考えると,emacs 内から submit できるとチャットの効率が大変あがるので便利な気がする.
  
行 676: 行 682:
 僕が投げた前後で,作者により秒で却下されてる issue があったが,現段階で 2 日経っても却下されてないので,少し考えてくれてるんじゃないかと期待して気長に待ってみようかと思う. 僕が投げた前後で,作者により秒で却下されてる issue があったが,現段階で 2 日経っても却下されてないので,少し考えてくれてるんじゃないかと期待して気長に待ってみようかと思う.
  
 +[2023-11-15]
 +
 +いちいち slack のウィンドウに戻るのが耐えられなかったので,slack にたいしての超アドホック対応を行なってみた.
 +大まかには,chrome を remote-debugging mode で起動し,websocket 越しに,今編集している textarea へ Enter のキーイベントを javscript 実行により送る.
 +chrome の remote debugging mode は,localhost からの接続しか設定できないため,WSL2 emacs から Windows の chrome の間では,この方法は実現不可能となる.WSL1 の場合,Linux コマンドも Windows と同じユーザランドで動作しているため,通信できる.
 +
 +
 +まず,chrome を debug モードで起動させる.Windows ならショートカットのプロパティなどで,''--debugging-port=9222'' を指定する.
 +
 +<code>
 +"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
 +</code>
 +
 +次に,emacs 上で,[[https://github.com/anticomputer/chrome.el|chrome.el]] を動かせるようにする.chrome.el は chrome と remote debugging mode 経由で通信して,タブ一覧を取得するものである.今回は,chrome.el を chrome から返ってくるタブ情報の json のパーサーのように扱う.
 +
 +次に,以下のコードが動かせるようにする.ちょうアドホックなので,このままでは多分動きません.「テキストを HTML 化しておく」と書いてある部分はまるごとなくても良いと思います.以下の2つの関数は,それぞれ別のオリジナル関数.
 +
 +  * (atomic-chrome-slack-send-buffer-modify) は,textarea 内のテキストにリストなどがあったら,対応する HTML に変化する関数
 +  * (my-atomic-chrome-send-buffer-text) atomic-chrome の中にある関数をラップしてるオリジナル関数.単に ghost-script の方に最新テキストを送るために呼び出している.
 +
 +<code lisp>
 +(defun skk/atomic-chrome-slack-submit-message ()
 +  (interactive)
 +  ;; もし *chrome-tabs* バッファの中で chrome.el が動いてなかったら,バッファ内で動作させる
 +  (setq edit-buffer (current-buffer))
 +  (chrome)
 +  ;; 自分のバッファに戻ってくる
 +  (switch-to-buffer edit-buffer)
 +
 +  ;; 作業バッファを *chrome-tabs* にする
 +  (set-buffer "*chrome-tabs*")
 +
 +  ;; *chrome-tabs* バッファ内のタブリストをアップデートする
 +  (chrome-retrieve-tabs)
 +
 +  ;; url が同じタブを見つける
 +  ;; ~atomic-chrome 側で取得している url をここまで持ってくる~
 +  (setq tmp chrome--cached-tabs)
 +  (setq keys ())
 +  (maphash (lambda (key value)
 +             (if (string-match "app.slack.com" (chrome-tab-url (gethash key tmp)))
 +                 (setq keys (cons key keys)))
 +             );lambda 
 +           tmp)
 +
 +  (message (format "num of slack chrome tab: %s" (length keys)))
 +  ;; assuming only 1 app.slack.com exists
 +  (setq value (gethash (car keys) tmp))
 +
 +  ;; テキストを HTML 化しておく
 +  ;; XXX [2023-11-11] save-current-buffer を利用しなければならないはず.
 +  (set-buffer edit-buffer)
 +  (setq tmp (atomic-chrome-slack-send-buffer-modify (buffer-substring-no-properties (point-min) (point-max))))
 +  (message (format "edited text %s" tmp))
 +  (set-buffer edit-buffer)
 +  (erase-buffer)
 +  (insert tmp)
 +  (my-atomic-chrome-send-buffer-text) 
 +
 +  ;; タブに対して websocket を貼る
 +  ;;(require 'websocket) ; 多分要らない
 +  (setq skk/websocket
 +        (websocket-open (concat
 +                         "ws://127.0.0.1:9222/devtools/page/"
 +                         (chrome-tab-id value))
 +                        :on-message (lambda (_websocket frame)
 +                                      (message "ws frame: %S"
 +                                               (websocket-frame-text frame)))
 +                        :on-error (lambda (_websocket frame)
 +                                    ;;(message "websocket error: %S" _websocket)
 +                                    (message "error: %s" (websocket-frame-text frame))
 +                                             )
 +                        :on-close   (lambda (_websocket)
 +                                      (message "websocket closed")
 +                                      )
 +
 +                        ))
 +
 +  ;; Enter を送信する js コードを送り込んで実行する
 +  (setq js-code "var hoge = document.getElementsByClassName(\\\"ql-editor\\\");
 +for (i=0; hoge.length>i; i++) { 
 +    if(hoge[i].innerHTML.length != 0){
 +        var push_hoge = hoge[i]; 
 +    }
 +}
 +push_hoge.dispatchEvent(new KeyboardEvent(\\\"keydown\\\", {
 +    key: \\\"Enter\\\", 
 +    keyCode: 13, 
 +  })); 
 +")
 +
 +  ;; XXX [2023-11-11] json-encode を使うべき.
 +  ;; (json-encode '(("id" . "10")
 +  ;;     ("method" . "Runtime.evaluate")
 +  ;;     ("params" . (("expression" "(\"hoge\")")))))
 +  (setq json-message (concat "{\"id\":1,\"method\":\"Runtime.evaluate\",\"params\":{\"expression\":\"" js-code "\"}}"))
 +
 +  (sleep-for 0.1) ;; XXX WHY!?!?
 +  ;;(message json-message)
 +  (websocket-send-text skk/websocket json-message)
 +
 +  (websocket-close skk/websocket)
 +
 +  ;; 送信したら,buffer 内をきれいにする
 +  (set-buffer edit-buffer)
 +  (erase-buffer)
 +
 +  )
 +</code>
 +
 +取り急ぎ,この関数を Ctrl-Enter に bind しておくと,なんとなく emacs 側からメッセージ送信ができている.できれば Ghost Script 側から,どの textarea 要素を編集しているのかの正確な情報が得られるなら,Enter のキーイベントを送りやすいし,JS コードを受けとってくれるなら,わざわざ remote-debugging を有効にしなくて良いので大変助かる,,,んだけどなあ.
 +
 +参考:
 +  * [[https://qiita.com/ikentoh/items/eeb413465f86f5b760d5websocket+chrome devtools protocolでスクリーンショットを取得する]] CDP protocol でどうやって JS コードを実行させるかの参考に.
 +  * [[https://blog.abrochard.com/websockets.html|Emacs & Websockets]] emacs で websocket 通信するための基礎.クライアント側もサーバ側も両方書いてある.
  
  
行 720: 行 841:
       "\\.\\(jpg\\|JPG\\|pptx\\|eps\\|pdf\\|dvi\\|tex\\|toc\\|png\\|PNG\\|svg\\)$")       "\\.\\(jpg\\|JPG\\|pptx\\|eps\\|pdf\\|dvi\\|tex\\|toc\\|png\\|PNG\\|svg\\)$")
 </code> </code>
- 
-=== - latex export === 
-org-mode で書いた文章を,LaTeX に export して,PDF にできる.頑張る人は論文まで書いている模様.MarkDown よりも org-mode の方が記述力が高い為,共同作業などをしない場合は,org-mode で記述する方が LaTeX コマンドを直接記述する割合を減らせる. 
- 
-<TBD> 
  
  
行 833: 行 949:
 ==== - インストール ==== ==== - インストール ====
  
-M-x package-list-package から markdown-mode を選択してインストール.+M-x package-list-package から markdown-mode を選択してインストール.use-package を使う場合は,自動でインストールされるので,手動でのインストールは必要無い
  
 ==== - 設定 ==== ==== - 設定 ====
行 854: 行 970:
  
  
-==== - pandoc で PDF 生成 [2023-10-12] ====+[2023-11-16] 
 + 
 +use-package を使うなら下記. 
 + 
 +<code lisp> 
 +(use-package markdown-mode 
 +  :ensure t 
 +  :after action-lock 
 +  :init 
 +  (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode)) 
 +  (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)) 
 +  :hook 
 +  (markdown-mode . turn-off-auto-fill) 
 +  (markdown-mode . action-lock-mode) 
 +  ;;(define-key markdown-mode-map "\C-cg" 'grep-checkbox-in-md) 
 +  :bind 
 +  (:map markdown-mode-map 
 +        ("C-c g" . grep-checkbox-in-md) 
 +        ("C-c C-y" . skk/markdown-paste-image)) 
 +  :custom-face 
 +  (markdown-header-face-1 ((t (:inherit org-level-1)))) 
 +  (markdown-header-face-2 ((t (:inherit org-level-2)))) 
 +  (markdown-header-face-3 ((t (:inherit org-level-3)))) 
 +  (markdown-header-face-4 ((t (:inherit org-level-4)))) 
 +  (markdown-header-face-5 ((t (:inherit org-level-5)))) 
 +  (markdown-header-face-6 ((t (:inherit org-level-6)))) 
 + 
 +  ) 
 +</code> 
 + 
 +==== - 画像を貼りつける ==== 
 +[2023-11-16] 
 + 
 +org-mode のところで作った関数を markdown-mode でも使えるようにした. 
 + 
 +<code lisp> 
 +(defun skk/markdown-paste-image ()  
 +  (interactive) 
 +  (skk/paste-image "markdown"
 +  ) 
 +</code> 
 + 
 +画像の表示/非表示の toggle は,''M-x markdown-toggle-inline-images'' で,''C-c C-x TAB''または ''C-c C-x C-i''. 
 + 
 +上のセクションに書いてあるように,''C-c C-y'' を ''skk/markdown-paste-image'' にマップしている. 
 + 
 +表示される画像の最大サイズを指定したい場合は,以下のようにする.ただし,imagemagick オプション付きでコンパイルされていないと,縮小は動作しない.Ubuntu の場合はソースからコンパイルしたら良さそう.FreeBSD の場合は,ports でインストールする際のオプションで指定しておくと良さそう. 
 + 
 +<code lisp> 
 +(setq markdown-max-image-size '(1000 . 700)) 
 +</code> 
 + 
 +==== - pandoc で markdown から PDF 生成 [2023-10-12] ====
  
 Windows のアプリで,markdown で書いたものを印刷するちょうどよいアプリが無い.アプリを買うのも嫌なので,pandoc を設定した.pandoc 自体の設定は [[https://www.sakaki.works/doku/doku.php?id=%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89#pandoc|pandoc]] 参照. Windows のアプリで,markdown で書いたものを印刷するちょうどよいアプリが無い.アプリを買うのも嫌なので,pandoc を設定した.pandoc 自体の設定は [[https://www.sakaki.works/doku/doku.php?id=%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89#pandoc|pandoc]] 参照.
行 878: 行 1046:
  (buffer-file-name)  (buffer-file-name)
  "--template=/home/skk/svn/howm/pandoc_default.latex"  "--template=/home/skk/svn/howm/pandoc_default.latex"
- "-o" (replace-regexp-in-string ".md" ".pdf" (buffer-file-name))+ "-o" (replace-regexp-in-string "\\\.md" ".pdf" (buffer-file-name))
  "--pdf-engine=lualatex"  "--pdf-engine=lualatex"
  "-V" "documentclass=bxjsarticle"  "-V" "documentclass=bxjsarticle"
行 888: 行 1056:
   )   )
 </code> </code>
 +
 +------------------------------------------------------------
 +===== - markdown-preview-mode =====
 +
 +==== - 概要 ====
 +基本的に,wiki/markdown/tex のような記法は,大体書いたものがどのように表示されるか理解しつつ利用するので,プレビューは必要ないが,人に見せながら編集するような場合,少し装飾された形で表示されると都合が良い.
 +
 +[[https://github.com/ancane/markdown-preview-mode|markdown-preview-mode]] は,emacs 上で 9000 番ポート(デフォルト)で http サーバを立ち上げ,websocket を利用してリアルタイムな情報のアップデートを実現している模様.以下が特徴だ,と書いてある.
 +
 +  * on save/idle preview update
 +  * scroll sync
 +  * custom/extra css and javascript
 +  * remote preview
 +  * multiple simultaneous previews
 +
 +CSS が適用できるのは当然として,スクロール追従をなんとなくしてくれるのは,思ったより便利かもしれない.
 +
 +==== - 設定 ====
 +
 +use-package の場合.
 +
 +<code lisp>
 +(use-package markdown-preview-mode
 +  :ensure t
 +  :config
 +  (setq markdown-command (list "/usr/bin/pandoc" "-f" "markdown_github"))
 +  (setq markdown-preview-stylesheets (list (concat homedir "howm/md/dtext-business/redmine.css"))))
 +</code>
 +
 +use-package を使わない場合.
 +
 +<code lisp>
 +(require 'markdown-preview-mode)
 +(setq markdown-command (list "/usr/bin/pandoc" "-f" "markdown_github"))
 +(setq markdown-preview-stylesheets (list (concat homedir "howm/md/dtext-business/redmine.css"))))
 +</code>
 +
 +pandoc 以外にも,markdown や multimarkdown という変換コマンドが存在している模様.pandoc はなんでも変換できるので便利だが,FreeBSD だと ports でインストールするのにでかいし,サイズもでかい.専用で考えるなら,他のコマンドを調べてもいいのかもしれない.
 +
 +今回は,redmine の markdown を編集したいので,似てる亜種の github markdown をベースにするために,''-f markdown_github'' を指定している.
 +
 +stylesheet は,redmine の css を持ってきて,以下の変更を加えると,ヘッダを除いた部分が redmine wiki とほぼ同じようになる.
 +
 +  + ''#content'' を ''#markdown-body'' に変更
 +  + body に background-color:#EEEEEE; を追加
 +
 +redmine の CSS は''https://redmine host/stylesheets/application.css'' に置かれているので,wget/fetch してくるとよい.
 +
 +きれいな CSS の方が良ければ,https://thomasf.github.io/solarized-css/ から CSS を持ってきてもよいかもしれない.
 +
 +使いかたは,MarkDown を編集しているバッファで ''M-x markdown-preview-mode'' と実行すると,ブラウザが開く.http://localhost:9000/?uuid=93fd19c6-0693-4c74-a1d8-62155f7bea4d こんな感じの URL になっているはず.
  
  
行 934: 行 1153:
  
 画像を保存するディレクトリは,僕は,howm で管理されているディレクトリ以下でしか利用しないだろうから,howm のディレクトリ構成を前提に作っているが,いろいろなところにファイルが点在する人は,WSL 環境と Windows 環境のパス名の変換を正しく行ない,特定のフォルダに画像を保存するようにした方がよいと思われる. 画像を保存するディレクトリは,僕は,howm で管理されているディレクトリ以下でしか利用しないだろうから,howm のディレクトリ構成を前提に作っているが,いろいろなところにファイルが点在する人は,WSL 環境と Windows 環境のパス名の変換を正しく行ない,特定のフォルダに画像を保存するようにした方がよいと思われる.
 +
 +[2023-11-16] markdown でも画像ペーストができるように,少し修正.
 +画像のインライン表示/非表示の切替えは,''M-x org-toggle-inline-images'' で,''C-c C-x C-v''
 +
  
 <code lisp> <code lisp>
 (setq org-image-actual-width 700) ;; emacs 内での画像サイズを実サイズにしない (setq org-image-actual-width 700) ;; emacs 内での画像サイズを実サイズにしない
  
-(defun skk/org-paste-image ()+(defun skk/org-paste-image ()  
 +  "wrapper to skk/paste-image" 
 +  (interactive) 
 +  (skk/paste-image "org"
 +  ) 
 + 
 +(defun skk/paste-image (mode)
   "Save a clipboard's screenshot into a time stamped unique-named file   "Save a clipboard's screenshot into a time stamped unique-named file
    in a specified directory and insert a link to this file."    in a specified directory and insert a link to this file."
行 944: 行 1173:
   ;; XXX ホスト毎に以下は変更する   ;; XXX ホスト毎に以下は変更する
   (setq filedir "C:\\Users\\skk\\svn\\howm\\img\\")   (setq filedir "C:\\Users\\skk\\svn\\howm\\img\\")
-  (setq unix_filedir "~/winhome/svn/howm/img/")+  (setq unix_filedir (concat homedir "howm/img/"))
  
   ;; latex に入れようとした時,dot が二つあると動作しないので,拡張子用以外の dot は _ にする.   ;; latex に入れようとした時,dot が二つあると動作しないので,拡張子用以外の dot は _ にする.
行 957: 行 1186:
   ;; ../../img/{filename}   ;; ../../img/{filename}
   (if (file-exists-p (concat unix_filedir filename))   (if (file-exists-p (concat unix_filedir filename))
-      (progn (insert (concat "[[" "../../img/" filename "]]")) +      (progn 
-             (org-display-inline-images))+        (cond 
 +         ((string= mode "org"
 +          (insert (concat "[[" "../../img/" filename "]]")) 
 +          (org-display-inline-images)) 
 +         ((string= mode "markdown"
 +          (insert (concat "![](../../img/" filename ")")) 
 +          (markdown-display-inline-images)) 
 +         ))
     (user-error     (user-error
      "Error pasting the image, make sure you have an image in the clipboard!"))      "Error pasting the image, make sure you have an image in the clipboard!"))
行 966: 行 1202:
  
 ==== - PDF 生成 ==== ==== - PDF 生成 ====
 +
 +org-mode で書いた文章は,HTML や MarkDown, LaTeX などに Export できる.
 +多少の文章を作るのに,Word や Google Spreadsheet で作成しても良いのだが,テキストベースで残っている方が保存の観点からは安心なので,共同作業が求められない場合,僕は emacs で文章を書き,LaTeX に export した上で PDF にする機能をちょいちょい使っている.org-mode は MarkDown よりも記述力が高いので,そこそこ複雑な文章でも作成しやすいような気がする.世の中的には MarkDown の方が流行っているけれども.
 +
 +=== - 基本設定 ===
 +
 +org-latex-pdf-process で,呼び出す latex コマンドを指定する.もし,参照を使いたい人は,bibtex などもここで指定する必要がある.また,latexmk などを使って呼び出す内容をまとめておくのもよいかもしれない.僕はコマンドラインから呼び出すことはほぼないので,latexmk まで整備する必要はない.
 +
 +org-latex-default-class は,org-latex-classes で指定された複数の class のうち,文章内で #+LATEX_CLASS が指定されてない時に利用されるデフォルトを指定しておく.
 +
 +org-latex-classes には,複数のクラスを記述して追加しておく.以下の例で言えば,''"article"''の部分をユニークな文字列にしておけば,いくつ登録しておいても良い.
 +
 +<code lisp>
 +(use-package org
 +  :ensure t ;; 多分イラナイ
 +  :after action-lock
 +  :init
 +  (setq org-latex-default-class "article")
 +  (setq org-latex-pdf-process  ; default 
 +        '("platex -shell-escape %f"
 +          "platex -shell-escape %f"
 +          "dvipdfmx %b.dvi"))
 +  (setq org-export-with-toc nil) ; \tableofcontents を出さない
 +  (setq org-export-latex-date-format "\\today") ; \date{} の中身を \today にする
 +  :hook
 +  (org-mode . turn-off-auto-fill)
 +  (org-mode . action-lock-mode)
 +  :config
 +  (add-hook 'org-mode-hook (lambda () (setq truncate-lines nil)))
 +  (add-hook 'org-export-before-processing-functions 'skk/latex-engine-setup)
 +  )
 +
 +(add-to-list 'org-latex-classes
 +             '("article"
 +               "\\documentclass[11pt,a4paper]{jarticle}
 +\\setlength{\\topmargin}{15mm}
 +\\addtolength{\\topmargin}{-1in}
 +\\setlength{\\oddsidemargin}{20mm}
 +\\addtolength{\\oddsidemargin}{-1in}
 +\\setlength{\\evensidemargin}{15mm}
 +\\addtolength{\\evensidemargin}{-1in}
 +\\setlength{\\textwidth}{170mm}
 +\\setlength{\\textheight}{254mm}
 +\\setlength{\\headsep}{0mm}
 +\\setlength{\\headheight}{0mm}
 +\\setlength{\\topskip}{0mm}
 +\\usepackage{otf}
 +\\usepackage{fancyhdr}
 +\\usepackage[dvipdfmx]{graphicx,color}
 +\\usepackage{xytree}
 +\\usepackage{indentfirst}
 +\\usepackage{minijs}
 +\\usepackage[T1]{fontenc}
 +\\usepackage{lmodern}
 +\\pagestyle{plain}
 +\\makeatletter
 +\\西暦"
 +               ("\\section{%s}" . "||section*{%s}")
 +               ("\\subsection{%s}" . "\\subsection*{%s}")
 +               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
 +               ("\\paragraph{%s}" . "\\paragraph*{%s}")
 +               ("\\subparagraph{%s}" . "\\subparagraph*{%s}")
 +               )
 +
 +)
 +
 +</code>
 +
 +org の文章をエクスポートするには,''C-c C-e'' と打ち,エクスポートのメニューを出す.LaTeX export は,''l'' で選択できて,''p'' とすると,PDF まで生成される.
 +
 +Windows の emacs で作業する際,PDF をオープンするために,毎回,howm で保存されてるフォルダにまでエクスプローラでたどり着くのがめんどくさいので,''C-x 3'' と打つことで編集しているフォルダを開けるように,以下のような設定も追加している.
 +
 +<code lisp>
 +(global-set-key "\C-c3" 'open-current-file-dir-with-explore)
 +(defun open-current-file-dir-with-explore ()
 +  (interactive)
 +  (my-action-lock-explorer-open (unix-path-to-windows (file-name-directory buffer-file-truename)))
 +  )
 +</code>
 +
 +実際に文章を書く際は,文章毎にいくつかオプションをつけることになる.次の項目に僕が使う代表的なものをいくつか載せておくが,クラスを選ぶには,''#+LATEX_CLASS: article'' のように指定すると良い.
 +
 +
 +=== - 文章毎のオプション ===
 +
 +<code>
 +#+TITLE: 文章のタイトル
 +#+AUTHOR: skk 
 +#+LATEX_CLASS: plainarticle
 +* セクション
 +内容内容.
 +</code>
 +
 +のように書く.オプションは以下のようなものがある.
 +
 +^ コマンド                     ^ 内容                                ^
 +| #+TITLE: タイトル文字        | LaTeX の \title.文章のタイトルを指定する                                   |
 +| #+AUTHOR: 著者               | 著者を指定                                                                  |
 +| #+DATE: \today               | 日付を指定.\today としておくと今日の日付になる                             |
 +| #+OPTIONS: H:2 toc:nil num:t |                                                                             |
 +| #+LANGUAGE: ja                                                                                           |
 +| #+LATEX_CLASS: plainarticle  | org-latex-class で命名した名前を指定し,適用される LaTeX ヘッダなどを選ぶ. |
  
 <TBD> <TBD>
  
-コマンドメモ: +=== - latex engine の切替え === 
-  * C-e C-p:変換先候補を出す + 
-    * l pPDF 出力する+僕は 2000 年代頭くらいの状態のまま LaTeX を使っていたので,platex を使っていたのだが,ここ最近は,lualatex,uplatex, pdflatex などが出てきていたり,latexmk のようなエンジンを切替えるしくみが出てきていたりする. 
 +これと同じように,documentclass で指定するクラスも,jarticle ではなく,jsarticle や bxjsarticle などを使うのが主流になってきている模様. 
 + 
 +年賀状で原の味フォントを使うのなんかも,platex のままで動作してたので,問題ないのかもしれないが,せっかくちょっとずついじるなら, jsarticle などを使っていってみたいと思う. 
 + 
 +ただ,その際,jarticle ベースで設定していたフォーマットと,jsarticle でこれから育てていくフォーマットを共存させたくなってくるので,latex class に応じて呼び出されるコマンドを変更したいと考えた. 
 + 
 +[[https://qiita.com/kawabata@github/items/1b56ec8284942ff2646b|org-mode で日本語LaTeXを出力する方法]]がかなり僕のやりたいことに近い気がするのだが,微妙に理解できないのと,使いかたも微妙に分からない.てか,マッチョすぎる.自分が latex-class で指定した名前に応じてエンジンが選べれば良い. 
 +[[https://kitchingroup.cheme.cmu.edu/blog/2013/05/05/Getting-keyword-options-in-org-files/|Getting keyword options in org-files]]を見てみると,org における keyword を取得するためコードが書いてあった.''#+'' で始まる行は,org のキーワードというものらしいので,これが取得できれば良さそう. 
 +ここのコード拝借して,以下のように書いてみたら,切替がうまく言ったような気がする. 
 + 
 +<code lisp> 
 + 
 +(use-package org 
 +  ...  
 +  :hook  
 +  (add-hook 'org-export-before-processing-functions 'skk/latex-engine-setup) 
 +
 + 
 +(defun skk/latex-engine-setup (engine) 
 +  (message "engine: %s" engine) 
 +  ;; [2025-01-12] 
 +  ;; https://kitchingroup.cheme.cmu.edu/blog/2013/05/05/Getting-keyword-options-in-org-files/ 
 +  (setq current-latex-class 
 +        (cdr (assoc "LATEX_CLASS" 
 +                    (org-element-map (org-element-parse-buffer 'element) 'keyword 
 +                      (lambda (keyword) (cons (org-element-property :key keyword) 
 +                                              (org-element-property :value keyword))))))) 
 +  (if (eq current-latex-class nil) 
 +      (setq current-latex-class org-latex-default-class)) 
 + 
 +  (cond ((string-match current-latex-class "article"
 +         (setq org-latex-pdf-process  ; default  
 +               '("platex -shell-escape %f" 
 +                 "platex -shell-escape %f" 
 +                 "dvipdfmx %b.dvi")) 
 +         (delete "\\hypersetup{setpagesize=false}" org-latex-packages-alist) 
 +         (delete "\\hypersetup{colorlinks=true}" org-latex-packages-alist) 
 +         (delete "\\hypersetup{linkcolor=blue}" org-latex-packages-alist)) 
 +        ((string-match current-latex-class "beamer"
 +         (setq org-latex-pdf-process  ; default  
 +               '("platex -shell-escape %f" 
 +                 "platex -shell-escape %f" 
 +                 "dvipdfmx %b.dvi")) 
 +         (delete "\\hypersetup{setpagesize=false}" org-latex-packages-alist) 
 +         (delete "\\hypersetup{colorlinks=true}" org-latex-packages-alist) 
 +         (delete "\\hypersetup{linkcolor=blue}" org-latex-packages-alist)) 
 +        ((string-match current-latex-class "jsarticle"
 +         (setq org-latex-pdf-process  ; default  
 +               '("uplatex -shell-escape %f" 
 +                 "uplatex -shell-escape %f" 
 +                 "dvipdfmx %b.dvi")) 
 +         (add-to-list 'org-latex-packages-alist "\\hypersetup{setpagesize=false}" t) 
 +         (add-to-list 'org-latex-packages-alist "\\hypersetup{colorlinks=true}" t) 
 +         (add-to-list 'org-latex-packages-alist "\\hypersetup{linkcolor=blue}" t)) 
 +        ) 
 +  ) 
 +</code> 
 + 
 +''org-export-before-processing-functions'' が,export がはじまる前に呼びされる hook である.以前は,''org-export-before-processing-hook'' という名前だったようなので,検索してるとこちらがよく引っかかるが,''M-x describe-functions'' で調べてみると,obsolute だよ,と書いてあるので,これから使う人は気をつけた方が良いかもしれない. 
 + 
 +''skk/latex-engine-setup'' では,文章内に ''LATEX_CLASS'' が指定してあればそれを利用るし,見つからなかったら default の class を利用する.文字列で分岐して,''org-latex-pdf-process''の中身を書き換える,ということをしている.''org-latex-package-alist''を操作しているのは,\CID をタイトルで利用しているとうまく動作しないことの実験なので,別のところで書く予定. 
 + 
 +備考[[https://stackoverflow.com/questions/55563546/emacs-org-mode-latex-simply-switch-between-pdflatex-xelatex-and-lualatex|Emacs org-mode latex - simply switch between pdflatex, xelatex and lualatex]] 見ると,''#+LATEX_COMPILER'' を指定し,latexmk に渡してさらっと変更してるみたい.これはこれで自由度高いし便利そうだけど,LATEX_CLASS で使いたいクラスを指定しつつ,コンパイラも指定しないといけなくなるから,うーん,どうだろう...好みかもしれないけど,僕は,今の自分の設定の方が良い気がするな. 
 + 
 +=== - beamer === 
 +LaTeX の beamer クラスは,スライドを LaTeX で作成するためのクラス.org で箇条書したものを beamer で export すると,スライドにしやすい.ox-beamer というパッケージを使いつつ export できる. 
 + 
 +beamer の LaTeX 的な記法は,[[latex]] に記載予定. 
 + 
 +<TBD>
  
 ==== - tbl 関係  ==== ==== - tbl 関係  ====
行 1839: 行 2247:
     * http://www.bookshelf.jp/soft/meadow_18.html     * http://www.bookshelf.jp/soft/meadow_18.html
  
 +====== - 自作機能 ======
 +===== - 今開いているファイルまたはフォルダをエクスプローラで開く =====
 +[2023-12-13]
 +WSL1 環境において emacs を利用中,Windows 側のファイルをいじることがあるが,そのファイルがあるフォルダをエクスプローラで開きたい時がある.たとえば,org-mode で文章を書いていて,PDF export した時,PDF を Acrobat など Windows 側のアプリで見る,など.
 +
 +以下のコードで,今開いているフォルダを開くならば,''C-c C-d o'',ファイルを Windows アプリで開きたい場合は,''C-c C-d f'' で開ける.
 +
 +<code lisp>
 +(global-set-key "\C-c\C-do" 'open-current-file-dir-with-explore)
 +(global-set-key "\C-c\C-df" 'open-current-file-with-explore)
 +
 +;; (set-drvfs-alist) は,https://www49.atwiki.jp/ntemacs/pages/74.html 参照.
 +(defun set-drvfs-alist ()
 +  (interactive)
 +  (setq drvfs-alist
 +        (mapcar
 +         (lambda (x)
 +           (when (string-match "\\(.*\\)|\\(.*?\\)/?$" x)
 +             (cons (match-string 1 x) (match-string 2 x))))
 +         (split-string (concat
 +                        ;; //wsl$ or //wsl.localhost パス情報の追加
 +                        (when (or (not (string-match "Microsoft" (shell-command-to-string "uname -v")))
 +                                  (>= (string-to-number (nth 1 (split-string operating-system-release "-"))) 18362))
 +                          (concat "/|" (shell-command-to-string "wslpath -m /")))
 +                        (shell-command-to-string
 +                         (concat
 +                          "mount | grep -E 'type (drvfs|cifs)' | sed -r 's/(.*) on (.*) type (drvfs|cifs) .*/\\2\\|\\1/' | sed 's!\\\\!/!g';"
 +                          "mount | grep 'aname=drvfs;' | sed -r 's/.* on (.*) type 9p .*;path=([^;]*);.*/\\1|\\2/' | sed 's!\\\\!/!g' | sed 's!|UNC/!|//!' | sed \"s!|UNC\\(.\\)!|//\\$(printf '%o' \\\\\\'\\1)!\" | sed 's/.*/echo \"&\"/' | sh")))
 +                       "\n" t))))
 +
 +(set-drvfs-alist)
 +
 +(defun my-action-lock-explorer-open (url)
 +  (message (concat "/select,/root," url))
 +  (start-process "explorer" "my-process" "/mnt/c/Windows/explorer.exe" (concat "/root,/select," url)))
 +(setq action-lock-default-rules
 +      (cons (action-lock-general 'my-action-lock-explorer-open
 +                                 "open://\\(.*\\)$"
 +                                 1)
 +            action-lock-default-rules))
 +
 +(defun unix-path-to-windows (unix-path)
 +  "WSL unix path を windows に変換する"
 +  (let ((unix-path-prefix "")
 +        (ret ""))
 +    (mapcar (lambda (x)
 +              (setq unix-path-prefix (car x))
 +              (unless (string= unix-path-prefix "/")
 +                (if (string-match unix-path-prefix unix-path)
 +                    (setq ret (concat 
 +                               (cdr (assoc unix-path-prefix drvfs-alist))
 +                               (replace-regexp-in-string "/" "\\\\"
 +                                                         (replace-regexp-in-string
 +                                                          unix-path-prefix "" unix-path )))))))
 +            drvfs-alist)
 +    ret))
 +
 +(defun open-current-file-dir-with-explore ()
 +  (interactive)
 +  (my-action-lock-explorer-open (unix-path-to-windows (file-name-directory buffer-file-truename))))
 +
 +(defun open-current-file-with-explore ()
 +  (interactive)
 +  (my-action-lock-explorer-open (unix-path-to-windows buffer-file-truename)))
 +</code>
  
  
行 1875: 行 2348:
     * apt などパッケージで入れても良い.     * apt などパッケージで入れても良い.
     * emacs 28 から登場した native compilation は,elisp の動作が 100 倍レベルで速くなるそうなので,もし利用している OS のパッケージが 28 になっていなかったら,自分でコンパイルして入れても良いかもしれない.     * emacs 28 から登場した native compilation は,elisp の動作が 100 倍レベルで速くなるそうなので,もし利用している OS のパッケージが 28 になっていなかったら,自分でコンパイルして入れても良いかもしれない.
 +
 +参考:
 +
 +<code bash>
 +% sudo apt-get install libwebkit2gtk-4.0-dev libgccjit-8-dev
 +% CPPFLAGS='-I/usr/lib/gcc/x86_64-linux-gnu/8/include' CFLAGS='-L/usr/lib/gcc/x86_64-linux-gnu/8' ./configure --with-native-compilation --with-xwidgets --prefix=$HOME/emacs29 --with-imagemagick
 +</code>
  
 ==== - X の設定 ==== ==== - X の設定 ====
行 2418: 行 2898:
  
 <code lisp> <code lisp>
-(replace-regexp-in-string ".md" ".pdf" (buffer-file-name))+(replace-regexp-in-string "\\\.md" ".pdf" (buffer-file-name))
 </code> </code>
  
emacs.1699372598.txt.gz · 最終更新: 2023/11/08 00:56 by skk
文書の先頭へ
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0