I use the % register to compile the current .tex file using pdflatex. I have this mapped to ww, where the file is first saved and then compiled.
map :ww :w <CR> :!pdflatex % <CR>
This works fine. Now I tried copying % to another register and then create similar mapping using the new register, but that doesn't work.
let @a=@%
map :ww :w <CR> :!pdflatex a <CR>
When I compile, I get the following error message:
! I can't find file `a'.
<*> a
However, when I check the register a using echo @a, the register has been created correctly. So I don't understand why this doesn't work. Please help.
P.S. My ultimate goal is to create a conditional mapping:
if % contains 'chapter':
map :ww :w <CR> :!pdflatex ../main.tex <CR>
else
map :ww :w <CR> :!pdflatex % <CR>
So that vim can handle the directory structure:
.
├── chapter1
│ ├── chapter1.tex
├── chapter2
│ ├── chapter2.tex
├── chapter3
│ ├── chapter3.tex
├── main.tex