TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  local s = [[\luaescapestring{\TeX}]]

After \luaescapestring{\TeX}, I think I should get

T\\kern -.1667em\\lower .5ex\\hbox {E}\\kern -.125emX

then this line will be converted into a string in Lua by using [[ ]] operation(at the same time, \\ will be \), thus,

s = "T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX"

but the result printed is

T\\kern -.1667em\\lower .5ex\\hbox {E}\\kern -.125emX


share|improve this question
up vote 8 down vote accepted

compare the different output:


  local s = [[\luaescapestring{\TeX}]]

  local s = "\luaescapestring{\TeX}"


T\\kern -.1667em\\lower .5ex\\hbox {E}\\kern -.125emX\\spacefactor \\@m 
T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX\spacefactor \@m 

With [[ ... ]] the backslash has no meaning and is escaped

share|improve this answer
Thanks for your reply, I get it. – Timothy Li May 7 '13 at 9:44

This is because [[...]] is a "safe" string, which is not what \luaescapestring is made for. This adds two backslashes to a string instead of one.

This is with regular Lua and is nothing special with LuaTeX:

a = [[foo \\ bar]]

b = "foo \\ bar"


foo \\ bar
foo \ bar

\luaescapestring{} replaces each backslash with two backslashes, regardless of the type of string you are defining (double bracket or double quote), because it doesn't know about it. That way you get two backslashes instead of one in the first string.

share|improve this answer
Thanks. Maybe I am too careless when reading the programming in Lua. – Timothy Li May 7 '13 at 9:43
@TimothyLi I always skip these details when leaning something, because I don't understand its implications. Only when I stumble upon issues like the one you mention, I re-read the documentation. – topskip May 7 '13 at 9:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.