Lilypond+TexLive(LuaLatex+lyluatex)+VS Code實現譜文混排


沒想到發文章反而更難被預覽了,那就復制一份到隨筆里好了。 

 

多次嘗試之下,終於實現了現階段譜文混排的最理想方式:

1. 綜合Latex的排版(還有廣泛適用人群)的優勢以及Lilypond的美觀優勢;

2. 在同一個編輯器里完成輸入、與編譯與瀏覽成品;

3. 譜面代碼可以像數學公式那樣有行間與多行顯示;

4. 不需要設置環境變量,不需要在命令行里操作。

接下來就演示Lilypond、TexLive和VS Code三劍客合璧的全過程吧!

 

-----------------------------------

1. Lilypond安裝

 lilypond提供樂譜方面的排版

下載地址 LilyPond – 人人的樂譜軟件: 下載

 

2 TexLive

TexLive提供文章排版

2.1 TexLive 安裝

TexLive清華大學鏡像下載見 Index of /CTAN/systems/texlive/Images/ | 清華大學開源軟件鏡像站 | Tsinghua Open Source Mirror

iso文件下載后直接雙擊打開,按下圖紅色框位置雙擊即可安裝

  

2.2 lyluatex安裝

lyluatex是在Latex里編譯lilypond代碼的關鍵,所以必須安裝。另外,它只能在LuaLatex下編譯,這一點后面會顯示出來。

打開 Tex Live Manager ,如下圖先選擇全部package,然后再搜索lyluatex,如果顯示已經安裝,則不需要再專門安裝lyluatex

 

 

3 VS code

VS Code 整合 Latex 和 Lilypond 的編輯環境

3.1 VS code 安裝

先下載:下載 Visual Studio Tools - 免費安裝 Windows、Mac、Linux (microsoft.com)

然后下載中文語言支持包,點擊方塊處,搜Chinese然后下載,如下圖

 

3.2 插件Latex Workshop

Latex Workshop用於支持Latex的編譯和運行在vs code上運行

3.2.1 安裝

搜Latex,然后找到 Latex Workshop 下載

 

 

3.2.2 配置

按 Ctrl + Shift + P,調出命令界面,進入首選項

 

 

在大括號中復制下面代碼(大括號本身不要復制進去),之后保存設置

{
   // Latex Workshop設置,從這里開始復制

    "latex-workshop.latex.autoBuild.run": "never",
    "latex-workshop.showContextMenu": true,
    "latex-workshop.intellisense.package.enabled": true,
    "latex-workshop.message.error.show": false,
    "latex-workshop.message.warning.show": false,
    "latex-workshop.latex.tools": [
        {
            "name": "lualatex",
            "command": "lualatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-shell-escape",    //這個命令行在網上的Latex Workshop設置里一般沒有,所以直接recipe會報錯
                "%DOCFILE%"
            ]
        }
    ],
       "latex-workshop.latex.recipes": [
        {
            "name": "LuaLaTeX",
            "tools": [
                "lualatex"
            ]
        },
    ],
  "latex-workshop.latex.clean.fileTypes": [
        "*.aux",
        "*.bbl",
        "*.blg",
        "*.idx",
        "*.ind",
        "*.lof",
        "*.lot",
        "*.out",
        "*.toc",
        "*.acn",
        "*.acr",
        "*.alg",
        "*.glg",
        "*.glo",
        "*.gls",
        "*.ist",
        "*.fls",
        "*.log",
        "*.fdb_latexmk"
    ],
        "latex-workshop.latex.autoClean.run": "onFailed",
        "latex-workshop.latex.recipe.default": "lastUsed",
        "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
        "latex-workshop.view.pdf.external.viewer.command": "C:\\Program Files (x86)\\Adobe\\Acrobat DC\\Acrobat\\Acrobat.exe",
        //雙引號里是pdf瀏覽器的執行文件,可以根據實際情況更換 "latex-workshop.view.pdf.viewer": "tab"

  //復制到這里結束 }

  

4 編譯文件

先在vs code里新建*.tex文件,編寫代碼:

\documentclass{article}

%% 開頭的設置可以確保中文隨便打,並且能支持用LuaLatex編譯。lyluatex只能通過LuaLatex來編譯 \usepackage[UTF8]{ctex} %% 使用lyluatex宏包,用以編譯lilypond語句 \usepackage{lyluatex} % geometry宏包可以用於靈活調整紙張大小 \usepackage{geometry} \geometry{a4paper, scale=0.65} %% 因為怕太密集,調整一下行距 \linespread{2.0} %% 正文 \begin{document} \title{使用lyluatex實現譜文混排} \author{lilypond 手殘粉} \maketitle 搭建好lilypond和latex的設置之后,就可以實現各種方式的打譜。例如: 只需要輸入 \textbackslash lilypond\{c' d' e'\},就能實現行中打譜 \lilypond{c' d' e'} 正如你所看到的那樣。 大括號里的語法和lilypond里的語法一致。例如,輸入\textbackslash lilypond\{ \textbackslash clef bass \textbackslash omit Staff.TimeSignature c' d' e' \} 就可以看到變成\underline{低音譜號}以及\underline{去掉拍號}后\lilypond{\clef bass \omit Staff.TimeSignature c' d' e'}的打譜效果。 也可以使用\textbackslash begin\{lilypond\} 和 \textbackslash end\{lilypond\} 直接進入lilypond環境,像編輯數學公式一樣編輯樂譜。 %% 空了一行 \vspace*{0.5\baselineskip} %% lilypond 環境 \begin{lilypond} music = \relative { c d e } \score { \new ChoirStaff \with { instrumentName = "2 Fl." } << \new Staff \transpose c c' \music  \new Staff { \clef bass \music } >> } \end{lilypond} 這樣,既可以利用Latex的編排優勢,又可以利用lilypond的打譜優勢,lilypond笨拙的文字排版終於可以說拜拜了。 \end{document}

因為是tex文件,建立后vs code的左側會出現tex字樣,點擊它,然后在COMMANDS一欄里點擊Recipe: LuaLaTex

 

 最后選擇View in VSCode Tab,就可以看到成果了

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM