3

ツールチェーンをR+TeXShopから、より効率的なSweave-> LaTeX-> SyncteX-> pdfview(skim)からemacs(具体的には、Aquamacs)AUCTeX-mode(emacs-speaks-を使用)に改造しています。 statsiticsのsweaveマイナーモード)。AUCTeX-> pdfviewチェーンのSyncteXですべてがうまく機能し、Sweaveから.pdfへのコンパイルですべてが正常に機能します。

最初のステップとしてSweaveを追加すると、問題が発生します。これで、.Rnwファイルが主要な元のドキュメントになり、生成される.texファイルは単なる中間ステップになります。もちろん、SyncteXがロックするのは.texファイルです。

.emacsファイルに加えた唯一の変更は、.Rnwから.pdfをビルドするための2つの新しいコマンドを登録することです。

誰かがemacsにSyncteXを使用して出力.pdfを.texではなく.Rnwに同期させる方法についてアドバイスを提供できますか?

ありがとう!

編集1: 警告:これは、午後中ずっと私の手探りの要約であることになりました。私は解決策に非常に近づきましたが、ドキュメントが見つからない最後のエラーに失敗しました。警告2:今日は私がemacsの内部の仕組みをこれほど深く調べたのは初めてでした。エラーや非効率性は必ずあります。

VitoshKaの答えは、私をそこまでの道のりのほとんどに導いてくれました。彼の推奨事項を私の.emacs(まあ、Preferences.elですが、機能的には同じです)ファイルに追加すると、Symbol’s value as variable is void: noweb-minor-mode-mapAquamacsが残りのinitファイルの前に.emacsファイルをロードするように見えるため、起動時にエラーが発生しました。

(require 'ess-site) (require 'ess-eldoc)VitoshKaの直前に追加してこれを修正しました(define-key noweb-minor-mode-map (kbd "\C-c \C-c") 'Rnw-command-master)。残念ながら、Aquamacsにはすでにバイナリのess-swv.elcファイルが付属しており、MnPリーダーを強制的にアクロリードします。そこで、ess-swv.elファイルの一部の次の編集を自分の.emacsの下部に追加しました。

(defun ess-makePDFandView ()
(interactive)
(setq namestem (substring (buffer-name) 0 (search ".Rnw" (buffer-name))))
(setq tex-filename (concat "\"" namestem "\".tex"))
(setq my-command-string (concat "pdflatex -synctex=1" tex-filename))
(shell-command my-command-string)
(setq my-command-string (concat "/Applications/Skim.app/Contents/MacOS/Skim \"" namestem ".pdf\" &"))
(shell-command my-command-string))

(define-key noweb-minor-mode-map "\M-nv" 'ess-makePDFandView)

これで、emacsは、 MnvまたはCcCcViewRETのいずれかを使用してemacsから正しいpdf名でスキムを起動します。まだもう1つ問題があります...

Command-Shift-Click in emacsはfilename.Rnw.pdfへの同期を試みます(ただし、エラーメッセージを破棄しても、少なくともpdfviewerで正しく同期されます)。Command-Shiftキーを押しながらpdfviewerをクリックしてソースに戻ると、emacsはfilename.texファイルを開き、それに同期します。幸い、CameronBrackenにはその修正があります。彼は、emacsの統合に完全に到達しているわけではありません。

そこで、このess-swv.elのハックを.emacsに追加しました。

(defun ess-swv-latex-rnw-sync ()
  "Run LaTeX on the product of Sweave()ing the current file."
  (interactive)
  (save-excursion
    (let* ((namestem (file-name-sans-extension (buffer-file-name)))
           (latex-filename (concat namestem ".tex"))
       (synctex-filename (concat namestem ".synctex.gz"))
           (tex-buf (get-buffer-create " *ESS-tex-output*"))
       (patchDVI-command-string (concat "Rscript -e \"library('patchDVI');patchSynctex('" synctex-filename "')\"")))
    (message "synctex string: %s" patchDVI-command-string) 
    (message "Running LaTeX on '%s' ..." latex-filename)
    (switch-to-buffer tex-buf)
    (call-process "latex" nil tex-buf 1 "-synctex=1 " latex-filename)
    (switch-to-buffer (buffer-name))
    (display-buffer tex-buf)
    (message "Finished running LaTeX" )
    (message "Running patchDVI...")
    (shell-command patchDVI-command-string))))

(define-key noweb-minor-mode-map "\M-nq" 'ess-swv-latex-rnw-sync)

DVIにパッチを適用して同期することが不足していると考えて...しかし、違います!Command-Shift-Clickでの上記と同じ動作...ess-swvのハッキングに戻ります。ess-makePDFandView関数を削除し、代わりに.emacsに以下を追加しました。

(defun ess-swv-PDF-rnw-sync (&optional pdflatex-cmd)
"From LaTeX file, create a PDF (via 'texi2pdf' or 'pdflatex', ...), by
default using the first entry of `ess-swv-pdflatex-commands' and display it."
(interactive
  (list
    (let ((def (elt ess-swv-pdflatex-commands 0)))
    (completing-read (format "pdf latex command (%s): " def)
                   ess-swv-pdflatex-commands ; <- collection to choose from
                   nil 'confirm ; or 'confirm-after-completion
                   nil nil def))))
(let* ((buf (buffer-name))
     (namestem (file-name-sans-extension (buffer-file-name)))
     (latex-filename (concat namestem ".tex"))
     (tex-buf (get-buffer-create " *ESS-tex-output*"))
     (pdfviewer (ess-get-pdf-viewer))
     (pdf-status)
     (cmdstr-win (format "start \"%s\" \"%s.pdf\""
                         pdfviewer namestem))
     (cmdstr (format "\"%s\" \"%s.pdf\" &" pdfviewer namestem)))
;;(shell-command (concat "pdflatex " latex-filename))
(message "Running '%s' on '%s' ..." pdflatex-cmd latex-filename)
(switch-to-buffer tex-buf)
(setq pdf-status
      (call-process pdflatex-cmd nil tex-buf 1 "-synctex=1 " 
                    (if (string= "texi2" (substring pdflatex-cmd 0 5))
                        ;; workaround (bug?): texi2pdf or texi2dvi *fail* to work with      full path:
                        (file-name-nondirectory latex-filename)
                      latex-filename)))
(if (not (= 0 pdf-status))
    (message "** OOPS: error in '%s' (%d)!" pdflatex-cmd pdf-status)
  ;; else: pdflatex probably ok
  (shell-command
   (concat (if (and ess-microsoft-p (w32-shell-dos-semantics))
               cmdstr-win
             cmdstr))))
(switch-to-buffer buf)
(display-buffer tex-buf)))

(define-key noweb-minor-mode-map "\M-nv" 'ess-swv-PDF-rnw-sync)

どんどん近づいていますが、スキムに渡すファイル名をauctexに指示する必要があります。だから私は弾丸を噛み、auctex-config.elを編集しました。私は既存のaquamacs-call-viewer関数の定義をコメントアウトし、それを自分のものに置き換えました。

(defun aquamacs-call-viewer (line source)
"Display current output file as PDF at LINE (as in file SOURCE).
Calls `aquamacs-tex-pdf-viewer' to display the PDF file using the
Skim AppleScript protocol."
  (cond 
    ((string= (file-name-extension (TeX-active-master)) "Rnw") 
      (let* ((full-file-name 
     (expand-file-name
      ;; as in TeX-view
      ;; C-c C-c view uses %o (from TeX-expand-list), which
      ;; is the same.
      (concat (file-name-sans-extension (TeX-active-master)) "." (TeX-output-extension))
      default-directory))
    (full-source-name
     (expand-file-name 
      (concat (file-name-sans-extension (source)) ".Rnw") ;; this is relative to the master 
      (file-name-directory (full-file-name)))))
   (message "full pdf name: %s" full-file-name)
   (message "full rnw sournce name: %s" full-source-name)
   (do-applescript
(format 
 "
 set theSink to POSIX file \"%s\" 
 set theSource to POSIX file \"%s\" 
 tell application \"%s\" 
 activate 
 open theSink 
 tell front document to go to TeX line %d from theSource%s
 end tell
 " 
 full-file-name full-source-name aquamacs-tex-pdf-viewer line
 ;; do not say "showing reading bar false" so users can override in future
 (cond ((eq t aquamacs-skim-show-reading-bar)
    " showing reading bar true")
       ((eq nil aquamacs-skim-show-reading-bar)
    " showing reading bar false")
       (t ""))))))
(t
 (let* ((full-file-name 
     (expand-file-name
      ;; as in TeX-view
      ;; C-c C-c view uses %o (from TeX-expand-list), which
      ;; is the same.
      (TeX-active-master (TeX-output-extension))
      default-directory))
    (full-source-name
     (expand-file-name 
      source ;; this is relative to the master 
      (file-name-directory full-file-name))))
   (message "IN OTHERWISE!! WAT: %s" (file-name-extension (TeX-active-master)))
   (do-applescript
(format 
 "
 set theSink to POSIX file \"%s\" 
 set theSource to POSIX file \"%s\" 
 tell application \"%s\" 
 activate 
 open theSink 
 tell front document to go to TeX line %d from theSource%s
 end tell
 " 
 full-file-name full-source-name aquamacs-tex-pdf-viewer line
 ;; do not say "showing reading bar false" so users can override in future
 (cond ((eq t aquamacs-skim-show-reading-bar)
    " showing reading bar true")
       ((eq nil aquamacs-skim-show-reading-bar)
    " showing reading bar false")
       (t ""))))))))

そしてもう1つの最終テスト(ツールチェーンのキーバインドを次のように変更したことに注意してください:Mn s-> Mn q-> Mn vこの順序でスウィーブ->ラテックス->ビュー[この最後のステップでは、pdflatexとtexi2pdfではありません])、すべてがビルドされ、エラーは発生せず、ビューアが起動します...

"Skim" "/Users/myname/text/testing/myfile.pdf": exited abnormally with code 127.

そして今、私は再び完全に失われました。スキムに精通している人はいますか?

編集2:まあ、エラー127は単にバイナリでファイルが見つかりません。どこかで私は道を壊したに違いない。そこで(setenv "PATH" (concat (getenv "PATH") ":" "/Applications/Skim.app/Contents/MacOS"))、auctex-config.elの上部近くに追加しました。これで、すべてがコンパイルされ、エラーなしで起動します...しかし、Command-Shift-クリックしてemacsを実行しても、Skimは応答しません(少なくともエラーは発生しません)。Command-Shift-Skimをクリックしても、emacsは.texファイルを強制的に開きます。

上で指摘したlispの重要な行で明らかな何かを見逃していない限り、残りの対話のほとんどはAppleScriptで行われるため、これは非常にAquamacs+Skim固有の質問になっていると思います。

4

1 に答える 1

3

明確にするために。RnwC-c C-c ファイルから、Sweave ( M-n s) の出力に対して AUCTeX コマンドを実行します。

問題は、Auctex が別のファイルを処理する必要があることを認識していないことです。これを認識させる方法は次のとおりです。

(defun Rnw-command-master (&optional override-confirm)
  "Run command on the current document.

If a prefix argument OVERRIDE-CONFIRM is given, confirmation will
depend on it being positive instead of the entry in `TeX-command-list'."
  (interactive "P")
  (let ((TeX-transient-master (concat
                               (file-name-sans-extension (buffer-file-name))
                               ".tex"))
        (TeX-master nil))
    (TeX-command (TeX-command-query (TeX-master-file)) 'TeX-master-file
                 override-confirm)))


(define-key noweb-minor-mode-map (kbd "\C-c \C-c") 'Rnw-command-master)

最初に Auctex を実行するには、少し追加の作業が必要です。Noweb サポートは現在、ESS で積極的に書き直されており、次のバージョンでは、AucTeX 統合を備えた完全に新しいシステムと、デフォルトでアクティブ化された他の多くの便利なものが用意されています。

于 2012-06-16T09:00:56.857 に答える