[texworks] Passing $synctexoption to Windows batch script?

Duncan Murdoch murdoch.duncan at gmail.com
Fri Feb 21 10:18:43 CET 2020


On 20/02/2020 8:56 p.m., Kyle Woodward wrote:
> Yes, this is a reasonable workaround. However, since TeXworks provides a 
> $synctexoption variable, wouldn't it be nice to use it? >
> The error is not in TeXworks itself, but in the Qt library. See lines 
> 400-401:
> https://code.woboq.org/qt5/qtbase/src/corelib/io/qprocess_win.cpp.html

It's harder than you think to get this kind of thing right.  The real 
problem is that command interpreters are inconsistent about how to 
handle special characters like quotes.  The code you refer to doesn't 
get it right for the Windows cmd.exe interpreter that handles .bat 
files, but that particular interpreter does some really weird and poorly 
documented command line handling.  I think the proper quoting for the 
context you're working in is to put a "^" ahead of the equal sign, i.e. 
on Windows in a .bat file it should pass

-synctex^=1

(as Philip said).  However, that's not the right kind of quoting if 
you're using some other command line interpreter.  If you want to read 
one attempt to describe the rules for this, see 
<https://stat.ethz.ch/R-manual/R-devel/library/base/html/shQuote.html>.

Duncan Murdoch

> 
> Thanks for all the help,
> Kyle
> 
> On Wed, Feb 19, 2020 at 3:09 PM Duncan Murdoch <murdoch.duncan at gmail.com 
> <mailto:murdoch.duncan at gmail.com>> wrote:
> 
>     On 19/02/2020 12:54 p.m., Kyle Woodward wrote:
>      > Hi,
>      >
>      > I am having trouble with a custom typesetting script (Windows
>     batch). I
>      > would like to pass $synctexoption to the script (in my case,
>     `-synctex=1`).
> 
>     If you are always using -synctex=1, why not hard code that in your
>     script, instead of trying to pass it as a command line argument?
>      >
>      > When I read command-line arguments, batch reads = as a delimiter.
>     I wind
>      > up with (e.g.) %1 being `-synctex` and %2 being `1`. If I try to
>     enclose
>      > $synctexoption in quotes, "$synctexoption", TeXworks escapes the
>      > quotation marks, giving %1 as `\"-synctex=1\"`, and thus %~1 is also
>      > `\"-synctex=1\"`. That is, batch cannot natively remove the
>     quotation marks.
> 
>     If you sometimes have other synctex options, why not code your batch
>     file to ignore %1 and put "-synctex=%2" in the right place within it?
> 
>     Duncan Murdoch
> 
> 
>      > There are many feasible workarounds within the batch script, but the
>      > most straightforward would be for TeXworks to not escape the
>     quotation
>      > marks. Is there an option somewhere to disable this escaping? (I
>     have
>      > disabled in-editor quotation mark escaping, but this is a
>     separate thing)
>      >
>      > [sorry for mixing backticks and quotes; I hope the problem is clear]
>      >
>      > Thanks,
>      > Kyle
> 



More information about the texworks mailing list.