Menu

#1369 Cannot pass inverse search command to Sumatra PDF from commandline.

None
fixed
nobody
1
2015-07-01
2015-06-26
Klaus
No

OS: Windows 8.1 (64bit)
TeXStudio: 2.9.4

On my system I need both LyX and TexStudio to use Sumatra PDF as viewer with inverse search.

In LyX the inverse search command is passed to Sumatra PDF using the -inverse-search argument, using the command line

SumatraPDF -reuse-instance -inverse-search "lyxeditor.cmd \"%f\" \"%l\"" PDFFILENAME

which by the way also works when entered directly in cmd.exe. The unescaped contents of the -inverse-search argument passed to TexStudio become

lyxeditor.cmd "%f" "%l"

When setting up TeXStudio in the same manner, except that %f,%l are replaced by %%f,%%l to account for TeXStudio's own placeholder expansions, i.e. setting the option Configure TeXstudio -> Commands > External PDF Viewer to

"C:\Program Files\SumatraPDF\SumatraPDF.exe" -inverse-search "C:\Program Files (x86)\TeXstudio\texstudio.exe \"%%f\" -line %%l" -reuse-instance %.pdf -forward-search ?c:me" @

Sumatra PDF will instead receive the unescaped contents

C:\Program Files (x86)\TeXstudio\texstudio.exe \%f\ -line %l

Using "" instead of \" to escape doublequotes (which works in some environments) results in

C:\Program Files (x86)\TeXstudio\texstudio.exe %f -line %l

so bottomline there is now method to pass the required doublequote characters to the -inverse-search argument. As a consequence, everytime I have used Lyx I need to correct the reverse-search setup manually to make it work with TexStudio.

Discussion

  • Klaus

    Klaus - 2015-06-26

    Regarding "" vs \": I think the former syntax worked in earlier versions of Windows, while now cmd.exe uses a more Unix'ish escaping style, where "A""B" is interpreted by executables as AB instead of A"B.

    Hence it might not be reproducible in older versions of Windows.

    In order to check the strings actually reaching the executable, I used two simple scripts tmp.cmd and tmp.bat which where used instead of SumatraPDF.exe for testing (see attachments).

     
  • Klaus

    Klaus - 2015-06-26

    Workaround:

    External PDF Viewer

    "PATH\TO\SCRIPTFILE.CMD" -inverse-search "C:\Program Files (x86)\TeXstudio\texstudio.exe \"%%f\" -line %%l" -reuse-instance %.pdf -forward-search ?c:me" @
    

    ``

    The referenced scriptfile

    @"C:\Program Files\SumatraPDF\SumatraPDF.exe" -inverse-search "\"C:\Program Files (x86)\TeXstudio\texstudio.exe\" \"%%f\" -line %%l" %*
    
     
  • Tim Hoffmann

    Tim Hoffmann - 2015-06-29

    Did you try a direct call of Sumatra using the command as described in the manual?

     
    • Klaus

      Klaus - 2015-07-01

      Sorry, I missed that here must be four instead of three double-quotes before the tex-studio path. It works, though I am confused why it requires a quadruple double quote.

      If this is some special syntax, it might be a good idea to document this in the "special chars" help text in the options dialog.

       
      • Tim Hoffmann

        Tim Hoffmann - 2015-07-01

        Indeed, triple double-quotes are the way literal quotes have to be supplied to QProcess, which is used internally. (Note: there's no shell involved in the execution of external programs).

        Instead of documenting this requirement, I've chosen to implement support for shell-style literal quotes \" as well (hg 5287 (887acf4b3b82)).

         
  • Tim Hoffmann

    Tim Hoffmann - 2015-07-01
    • status: open --> fixed
    • Group: -->
     

Log in to post a comment.