Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling files with extensions other than .tex #4457

Open
zhengxinhao-comp opened this issue Nov 11, 2024 · 6 comments
Open

Compiling files with extensions other than .tex #4457

zhengxinhao-comp opened this issue Nov 11, 2024 · 6 comments
Assignees

Comments

@zhengxinhao-comp
Copy link

zhengxinhao-comp commented Nov 11, 2024

Environment

  • Operating System: Windows 11
  • Visual Studio Code Version: 1.95.2
  • LaTeX Workshop Version: 10.5.6
  • TeX Distribution Version: TeX Live 2024

The Issue

LaTeX Workshop refuses to compile source file with file extension other than .tex.

Reproduction Steps

I use a music typesetter called LilyPond. The way it corporates with LaTeX is that I input the LaTeX source code with LilyPond code in the environment \begin{lilypond} \end{lilypond}, and save the file with the extension .lytex, and use the command lilypond-book to compile it. lilypond-book would compile the .lytex file to a .tex file, then the user can use a regular LaTeX command to compile the intermediate file to PDF.

I've set the following tool

        {
            "name": "lilypond-book",
            "command": "lilypond-book",
            "args": [
                "%DOC_EXT%"
            ],
            "env": {}
        }

and recipe

        {
            "name": "Compile lytex",
            "tools": [
                "lilypond-book",
                "xelatexmk"
            ]
        }

to automate the task but I can't get the compilation running when I click the recipe in LaTeX panel.

Expected Behavior

LaTeX Workshop should be able to compile source file with extensions other than ".tex". I don't know if it's possible, or it would be better to have an option in the settings defining file extensions LaTeX Workshop recognizes and is able to compile.

@James-Yu
Copy link
Owner

Compiling files other than tex is out of scope of this extension. You may resort to vscode tasks for the job.

@jlelong
Copy link
Collaborator

jlelong commented Nov 12, 2024

It reminds me of what I implemented to support literate programming for the R and Julia languages.
@James-Yu If you are fine with it, I can try to make a PR to support to .lytex. From my point of view, it is not so much a matter of compiling the file as there are alternative approaches but rather to make other features such as intellisense work.

The first step is to closely look at the structure of a .lytex file to determine if it is feasible with little modification. @zhengxinhao-comp could you provide a representative example of such a file?

@James-Yu
Copy link
Owner

Yeah I’m totally fine with that 👍

@James-Yu James-Yu reopened this Nov 12, 2024
@zhengxinhao-comp
Copy link
Author

zhengxinhao-comp commented Nov 12, 2024

It reminds me of what I implemented to support literate programming for the R and Julia languages. @James-Yu If you are fine with it, I can try to make a PR to support to .lytex. From my point of view, it is not so much a matter of compiling the file as there are alternative approaches but rather to make other features such as intellisense work.

The first step is to closely look at the structure of a .lytex file to determine if it is feasible with little modification. @zhengxinhao-comp could you provide a representative example of such a file?

Thanks! .lytex works pretty much like a regular LaTeX package but it uses an external program to typeset music notation. Here is an example:

\documentclass{article}
\begin{document}
Here is an excerpt of using LilyPond with \LaTeX :

\begin{lilypond}
% Here goes the LilyPond code
\relative c' { c c g' g | a a g2 | f4 f e e | d d c2 \bar "||" }
\end{lilypond}
\end{document}

Save the file to example.lytex and run lilypond-book example.lytex, it will call the LilyPond application installed in the system and generate example.tex with the following code:

\documentclass{article}
\usepackage{graphics}
\begin{document}
Here is an excerpt of using LilyPond with \LaTeX :

{%
\parindent 0pt
\noindent
\ifx\preLilyPondExample \undefined
\else
  \expandafter\preLilyPondExample
\fi
\def\lilypondbook{}%
\input{f2/lily-477c6dad-systems.tex}%
\ifx\postLilyPondExample \undefined
\else
  \expandafter\postLilyPondExample
\fi
}
\end{document}

and a bunch of other files, which include an .eps file which contains the music excerpt. Then I can just run xelatex example.tex to get the result PDF:
image

lilypond-book provides the following commands and environments to include music in LaTeX files:

  • the \lilypond{…} command to directly enter short LilyPond code,
  • the \begin{lilypond}…\end{lilypond} environment to directly enter longer LilyPond code,
  • the \lilypondfile{…} command to insert a LilyPond file,
  • the \musicxmlfile{…} command to insert a MusicXML file, which gets processed by musicxml2ly and lilypond.

See more information here.

lilypond-book supports other document preparation systems like Texinfo and DocBook. The extension .lytex tells lilypond-book that it is a LaTeX file. Technically, to bypass the limit, I can still name the source code with LilyPond excerpt with the extension .tex and run lilypond-book --format=latex --output=dir to inform lilypond-book the file type I'm dealing with. See more information here.

@jlelong
Copy link
Collaborator

jlelong commented Nov 21, 2024

I have just made a PR to add a new configuration variable to enable users to declare any extension as a LaTeX extension.

To deal with the current issue, other steps have to be taken

  • Declare lilypond environments as verbatim by adding lilypond to latex-workshop.latex.verbatimEnvs to tell LW not to parse the content of lilypond environments.

  • Add a new recipe to latex-workshop.latex.recipes

       {
            "name": "Compile lylipond files",
            "tools": [
                  "ly2tex",
                  "latexmk"
            ]
       }
  • Add a new tool to latex-workshop.latex.tools

      {
             "name": "ly2tex",
             "command": "lylipond-book",
             "args": [
                  "%DOC_EXT%"
             ],
             "env": {}
      }

@zhengxinhao-comp what kind of syntax highlighting do you expect for the lylipond environments. I am not sure considering the content as standard LaTeX is a good idea. Would it be better to just apply no syntax highlighting?

@jlelong
Copy link
Collaborator

jlelong commented Nov 25, 2024

@zhengxinhao-comp Just a gentle reminder. What kind of syntax highlighting would you expect for lylipond environments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants