1

私は、emacs+AucTeX を使って LaTeX ファイルを書き込んでいます。ファイルの下部には、.texいくつかのローカル変数があります。

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "master-file"
%%% End: 

これらは、ファイルを作成するときに AucTeX によって追加されます。

私がやりたいのは、次のことを行う Lisp 関数を書くことです。

  1. 特定のローカル変数が存在するかどうかを確認します (それを呼び出しますpdf-copy-path) 。
  2. この変数が存在する場合は、それが整形式 (unix) のディレクトリ パスであるかどうかを確認します。
  3. そうであれば、出力pdfをそのフォルダーにコピーします

.tex出力 pdf は現在のファイルと同じ名前ですが、.pdf拡張子が付きます。

私のlisp-fuはこれに対応しておらず、関数にローカル変数の現在のファイルをチェックさせる方法がわかりません。任意のポインタをいただければ幸いです。

私はこの質問に SU ではなく SO を選びました。これは何よりも Lisp プログラミングに関する質問のように思われるからです。

4

1 に答える 1

2

あなたが本当に完全な解決策を望んでいるのか、それとももっと自分で探求したいのかはわかりませんが、ここに役立つはずのいくつかのことがあります。行き詰まったら、もう一度投稿してください。

  • 変数file-local-variables-alistは、探している値を保持します。関数の1つを使用assocして、リストからpdf-copy-pathの値を取得する必要があります。

  • file-exists-p関数を使用してファイルが存在するかどうか、およびfile-attributes(最初の要素)を含むディレクトリであるかどうかを確認できます。

  • 次に、を使用しますcopy-file

(FWIW、出力PDF出力は現在のファイルではなくTeX-masterと一致すると思います。)

[2011年3月24日編集-コードを提供]

これは、次のようなローカル変数ブロックを持つTeXファイルで機能するはずです。

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "master"
%%% pdf-copy-path: "/pdf/copy/path"
%%% End: 

TeX-master値とpdf-copy-path値を二重引用符で囲んでいることに注意してください。TeX-masterはt

(defun copy-master-pdf ()
  "Copies the TeX master pdf file into the path defined by the
file-local variable `pdf-copy-path', given that both exist."
  (interactive)
  ;; make sure we have local variables, and the right ones
  (when (and (boundp 'file-local-variables-alist)
             (assoc 'pdf-copy-path file-local-variables-alist)
             (assoc 'TeX-master file-local-variables-alist))
    (let* ((path (cdr (assoc 'pdf-copy-path file-local-variables-alist)))
           (master (cdr (assoc 'TeX-master file-local-variables-alist)))
           (pdf (cond ((stringp master)
                      ;; When master is a string, it should name another file.
                       (concat (file-name-sans-extension master) ".pdf"))
                      ((and master (buffer-file-name))
                      ;; When master is t, the current file is the master.
                       (concat (file-name-sans-extension buffer-file-name) ".pdf"))
                      (t ""))))
      (when (and (file-exists-p pdf)
                 (file-directory-p path))
        ;; The 1 tells copy-file to ask before clobbering
        (copy-file pdf path 1)))))
于 2011-02-14T15:25:28.923 に答える