自動複製和貼上?

自動複製和貼上?

我找到了一個可以將PDF轉換為LaTeX的程序,所以我有.tex各種數學教科書的文件。我想列出書中的定理列表,因此我一直從.tex文件中手動複製和貼上。有什麼辦法可以自動化這個過程嗎?例如,我可以複製以定理一詞開頭的每一行/段落。具體來說,我正在使用 LyX。

答案1

這可能不適用於 LyX(我還沒有測試過),但這裡有一個解決方案,可以將特定環境從來源檔案剝離到目標檔案中。定義函數:

(require 'cl) ; place your cursor after this paren and pres C-x C-e

(defun **strip-stuff (file &optional environments)
  "Takes the current file and strips every environment from
`ENVIRONMENTS` into `FILE`."
  (interactive "FFile name: \nxList of Environments (\"one\" \"two\" \"etc\"): ")
  (if (every 'stringp environments)
      (progn
        (beginning-of-buffer)
        (let ((search-regex (concat "\\\\begin{"
                                    (mapconcat 'identity
                                               environments
                                               "\\|")
                                    "}")))
          (while (search-forward-regexp search-regex nil t)
            (LaTeX-mark-environment)
            (copy-region-as-kill (point) (mark))
            (save-excursion
              (find-file file)
              (end-of-buffer)
              (yank)
              (newline 2)
              (save-buffer)
              (previous-buffer))
            (exchange-point-and-mark)))
        (message "Strip complete.  Check %s for the output." file))
    (message (concat "The environment variable you provided"
                     " was not a list of strings.")))) ; here too

然後將其套用到M-x **strip-stuff您的文件中 ( )。

我已經發布了此工作的視頻示例在YouTube上。它示範如何使用簡單的鍵盤巨集自動將該功能套用至多個檔案。

答案2

這不是 TeX 相關的問題。如果您只想剪下和貼上幾個段落,您將需要熟悉一個嚴肅的文字編輯器。我使用 nvi,但通常您會在考慮其他編輯器之前先檢查 Vim 和 Emacs。對於大規模自動化,您將需要在清單中使用來學習 sed(流編輯器)和 shell 腳本或某種腳本語言(例如 Perl、Python)。假設學習正規表示式。

請注意,缺乏本機腳本語言將使 Windows 作業系統無法進行任何嚴肅的文字處理,因此您將不得不使用某種 UNIX 或類 UNIX 作業系統。

免責聲明:我聽說過 Windows 版的 PowerShell,但從未真正對該作業系統做過任何認真的事情。

相關內容