On Wed, Jun 09, 2021 at 04:03:09PM +0800, Hongyi Zhao wrote: > On Wed, Jun 9, 2021 at 3:01 PM Jean Louis wrote: > > > > * Hongyi Zhao [2021-06-09 09:50]: > > > I found the following command from > > > : > > > > > > "curl -s https://api.mathpix.com/v3/latex -X POST -H \"app_id: %s\" -H > > > \"app_key: %s\" -H \"Content-Type: application/json\" --data > > > \"{\\\"src\\\":\\\"%s\\\",\\\"formats\\\": > > > [\\\"latex_styled\\\"],\\\"format_options\\\":{\\\"latex_styled\\\": > > > {\\\"transforms\\\": [\\\"rm_spaces\\\"]}}}\"" > > > > > > I want to obtain its normal version and test it under the system's > > > shell terminal. Any hints for deleting the escape characters correctly > > > from the above command in Emacs way? > > > > You should use the function `call-process' as it will help with > > quoting: > > > > (call-process "curl" nil nil nil "-s" "https://api.mathpix.com/v3/latex" > > "-X" "POST" "-H" (format "app_id: %s" id) > > "-H" (format "app_key: %s" key) > > "-H" "Content-Type: application/json" > > "--data" "{\"src\":\"%s\", > > \"formats\": [\"latex_styled\"], > > \"format_options\": {\"latex_styled\": > > {\"transforms\": [\"rm_spaces\"]}}}") > > You've stripped the escaping characters out manually in the above code. It's a bit more complex than that: The above is one big string in Emacs lisp which is to be passed to a shell. So it has an "outer" syntax, to be interpreted by the Emacs lisp reader, and an "inner" to be interpreted by the shell reader. The below is split into several strings (call-process takes a list of arguments, which are passed to exec), so no "shell escaping" is necessary. But since the individual arguments are represented as Emacs lisp strings, they need that escaping. So in a way yes, one layer of escaping has been removed, but it's the lower layer, the shell escaping. It just looks very similar to the upper (lisp) layer :-) Cheers - t