Question: Can I call Git-Bash to issue a command from WSL? Detailed contexts go between the two dividers. (Simple solution appended towards the end of this question.)
I use an alias to compile all my
*.tex documents, using Git-Bash on
Windows 10. In my
c:/users/UserName/.bashrc, I have mapped:
alias lmk='latexmk -pvc -pdf --synctex=1 -src-specials -silent -time -interaction=nonstopmode'
With a native
Gvim.exe editor and a Git-Bash instance that hosts the
latexmk command, I no longer need to bother with the tedious compilation process.
However, when I issue the same
latexmk command through WSL, I can no longer perform forward search and backward search. Some options for the compiler will write to the PDF (or its syntex file), mapping all lines on the PDF to the lines from the source file detailed in WSL-flavored paths. Another way to fix these is to: either opt completely into the WSL world, where I use the native editor + PDF viewer (which is completely new to me), or, to debug further into the compiler and see if I can swap out all the WSL-flavored paths into Windows-flavored paths (which is again, time-consuming).
A simple solution would be, to somehow call Git-Bash from WSL, whereby passing the
lmk commands to the Git-Bash as command line arguments?
Aside from the details, in general, is Git-Bash some executable that I can call directly from WSL? If so, how to tell WSL that I would like to run the following "thing"? On my machine, I can find Git-Bash as:
"C:\Program Files\Git\git-bash.exe". I tried to pass
/mnt/c/Program\ Files/Git/git-bash.exe to WSL, and it has only kindly opened a stand-alone Git Bash window.
One-liner solution using zsh + GitBash
zsh as my default shell for WSL, and here goes the function that I defined to
lmk TexFilename.tex directly callable from WSL's command line:
"$(wslpath "C:\Program Files\Git\git-bash.exe")" --hide -c "lmk $1"
# Note, the `lmk` here is actually alias from Git-Bash, as defined in: c:/users/UserName/.
The following line makes terminating the hidden
perl process handy: issuing
lmk_kill shall quite all running compilers (via
latexmk, a perl-script).
alias lmk_kill="powershell.exe kill -n perl"
To summarize: with the new
zsh function, I am compiling
*.tex files from WSL as if I am using the native MikTeX compilers on Windows. This works well with my current settings of GVIM + Sumatra, where both forward and backward search are fully functional.
Even simpler solution: host
latexmk through PowerShell
For details, refer to this answer below.
alias lmk='powershell.exe -c latexmk -pvc -pdf --synctex=-1 -src-specials -silent -time -interaction=nonstopmode'
main.tex files anywhere, say, in a pane of Tmux session on WSL, using simple command