2

I looked around for a long time but did not find any solution for that. On my Unix system (Ubuntu), using LaTeX-suite, I need to escape some characters in file names for compilation, say parenthesis (,) and comma ,.

I modified a bit my compilation script following LaTex-vim cannot compile files with spaces in name and now spaces are indeed escaped. The problem is that fnameescape() does not escape commas or parenthesis.

Is there any way I could add ( ) and , as new characters to be escaped by that function ?

If not, is there any way I can change my line

let mainfname = fnameescape(Tex_GetMainFileName(':p:t'))

in compiler.vim to also escape commas and parenthesis ?

Thanks a lot !


EDIT : Here is a temporary solution I found, seems to work but since I'm not an expert it might lead to further problems at some point. For the moment, it worked with the following filename

DM8 - Devoir libre (fonctions, probas).tex

In ftplugin/latex-suite/compiler.vim at line 112 I added the two times three subsitute() lines by hand :

if exists('b:fragmentFile')
    let mainfname = fnameescape(expand('%:p:t'))

    let mainfname = substitute(mainfname,'(', '\\(','g')
    let mainfname = substitute(mainfname,')', '\\)','g')
    let mainfname = substitute(mainfname,',', '\\,','g')

    call Tex_CD(expand('%:p:h'))
else
    let mainfname = fnameescape(Tex_GetMainFileName(':p:t'))

    let mainfname = substitute(mainfname,'(', '\\(','g')
    let mainfname = substitute(mainfname,')', '\\)','g')
    let mainfname = substitute(mainfname,',', '\\,','g')
LLD
  • 21
  • 2

1 Answers1

3

I think you're looking for :h escape()

escape({string}, {chars})               *escape()*
        Escape the characters in {chars} that occur in {string} with a
        backslash.

So your line could be something like this (and you can remove the substitute calls)

let mainfname = escape(fnameescape(expand('%:p:t')), '(),')

Note that I still use fnameescape() because according to :h fnameescape() the characters escaped by function are system specific and you probably don't want to maintain that by yourself.

statox
  • 49,782
  • 19
  • 148
  • 225