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

Allow custom argument to compilation on the fly #2836

Closed
BertrandSim opened this issue Nov 24, 2023 · 10 comments
Closed

Allow custom argument to compilation on the fly #2836

BertrandSim opened this issue Nov 24, 2023 · 10 comments

Comments

@BertrandSim
Copy link
Contributor

BertrandSim commented Nov 24, 2023

Good afternoon! I am enjoying vimtex so far (for several years now). It has been very helpful to my work.

Is your feature request related to a problem? Please describe it.
Currently I am posting problem sets, and thereafter, adding the solutions right after each question.
By using a tex macro (using xparse), the solutions can be shown or hidden, as defined by the \jobname.

  • To generate the questions with the solutions, simply append -soln to the jobname, i.e.

    !latexmk % -jobname=%:r-soln
  • To show only the questions, compile as per usual (using :VimtexCompile).

The tex macro in the preamble handles this:

\usepackage{xstring}
\IfEndWith*{\jobname}{-soln}{%
  % Solution environment 
  \NewDocumentEnvironment{solution}{O{\textit} +b}%
    {\par #1{Solution:} #2}{}
}{%
  % Empty Solution environment
  \NewDocumentEnvironment{solution}{+b}{}{} 
}

When compiled, this produces <file>.pdf, or <file>-soln.pdf, depending on the \jobname.

Describe the solution you'd like
Would there be a way to add an argument such as -jobname=%:soln on-the-fly? One possibility is to allow :VimtexCompile to take in arguments, ie. :VimtexCompile -jobname=%:r-soln, which would pass the jobname argument to g:vimtex_compiler_latexmk.

Describe alternatives you've considered

  • The option g:vimtex_compiler_latexmk could be modified, but the added argument becomes permanent, which is undesirable for a questions only output.
  • Currently I am using the shell command
    !latexmk % -jobname=%:r-soln, but the shell output quickly clutters the vim window after this is run.

Additional context
Neovim 0.8, lualatex.

@lervag
Copy link
Owner

lervag commented Nov 25, 2023

Good afternoon! I am enjoying vimtex so far (for several years now). It has been very helpful to my work.

Glad to hear it!

One possibility is to allow :VimtexCompile to take in arguments, ie. :VimtexCompile -jobname=%:r-soln, which would pass the jobname argument to g:vimtex_compiler_latexmk.

I think it seems like a good idea to allow an argument to :VimtexCompile. I propose the following "specification":

                                             *:VimtexCompile*
                                             *<plug>(vimtex-compile)*
:VimtexCompile [options]  If the compiler supports and is set to run in
                          continuous mode, then this command works as
                          a compiler toggle. If not, this command will run
                          a single shot compilation.

                          Arguments to the command will be passed on as options
                          when starting the compiler. This allows the user to
                          start the compiler with different options without
                          changing any configuration. That is, if the user uses
                          the latexmk backend, then adding any option argument
                          is equivalent to adding them to the `'options'` key
                          of |g:vimtex_compiler_latexmk|.

@lervag
Copy link
Owner

lervag commented Nov 25, 2023

I've pushed a PR for this; it would be nice if you could test if it does what you want.

@BertrandSim
Copy link
Contributor Author

BertrandSim commented Nov 27, 2023

Thank you for the changes; I've checked out the branch feat/vimtex-compile-options on my end. The compilation completed immediately, however no output was produced.

Running :VimtexCompile (without arguments) gave <file>.pdf, but running :VimtexCompile -jobname=%:r=soln gave no output.

@lervag
Copy link
Owner

lervag commented Nov 27, 2023

but running :VimtexCompile -jobname=%:r=soln gave no output.

After running this, what do you see in :VimtexInfo under the compile command? And what's the output in :VimtexCompileOutput?

Notice that doing :VimtexCompile toggles compilation, so the first invocation starts compilation whereas the second will stop it.

@BertrandSim
Copy link
Contributor Author

Output of :VimtexInfo, compiler

  compiler: latexmk
    engine: -lualatex
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    aux_dir: .auxfiles
    callback: 1
    continuous: 0
    executable: latexmk
    job: 
      jobid: 6
      output: /tmp/nvim.bertrand-sim/bU0WfQ/0
      cmd: max_print_line=2000 latexmk -verbose -file-line-error -synctex=1 -interaction=nonstopmode -jobname=%:r-soln -lualatex -emulate-aux-dir -auxdir=.auxfiles 'pset08.tex'

and :VimtexCompileOutput:

Rc files read:
  /etc/LatexMk
  /home/bertrand-sim/.latexmkrc
Latexmk: This is Latexmk, John Collins, 4 Apr. 2023. Version 4.80.

Latexmk: Jobname '%:r-soln' contains placeholder other than %A.
Use
   latexmk -help
to get usage information

@lervag
Copy link
Owner

lervag commented Nov 27, 2023

Ah, so it seems that the %:r is not expanded here. Thus, for now, if you avoid using % it should work, I think.

I'll look into how I can make the %s available in the arguments.

@BertrandSim
Copy link
Contributor Author

Agreed, and to confirm this, running VimtexCompile -jobname=pset08-soln (the file is called pset08.tex) gives the desired output.

@lervag
Copy link
Owner

lervag commented Nov 27, 2023

Ok, I've tried to include expansion as well; please pull the latest version of the branch and test again.

@BertrandSim
Copy link
Contributor Author

It works well, thank you!

lervag added a commit that referenced this issue Nov 29, 2023
lervag added a commit that referenced this issue Nov 29, 2023
@lervag
Copy link
Owner

lervag commented Nov 29, 2023

Great; I've merged the PR. Let me know if you find any bugs :)

@lervag lervag closed this as completed Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants