[luatex] Getting all symbols

Joseph Wright joseph.wright at morningstar2.co.uk
Tue Jun 12 17:04:26 CEST 2012

On 12/06/2012 15:29, Sensei wrote:
> Thanks for the info!
>
> I am puzzled by the output, though. When I dump the contents to a file,
> with the following:
>
> \documentclass{article}
>
> \begin{document}
> \directlua{
>  local f = io.open("hash.txt", "w")
>  for name in pairs(tex.hashtokens()) do
>      f:write(name .. ";;;;")
>  end
>  f:close()}
> \end{document}

I would use

f:write(name .. "\string\n")

to write one csname per line in your output.

> I can't open it with ease with a text editor: it complains it has a
> corrupt UTF-8 enconding. I am using ";;;;" since I don't know how to add
> a new line safely here: sorry for this inconvenience.

Works fine for me.

> Moreover, I can find symbols that are common, for example begin, textit,
> equation, but they're all without a backslash. How can I distinguish
> between \ commands and known symbols? For example, begin is a command,
> \begin, and it may accept the environment flushleft, but not \flushleft.

The escape character (usually "\") is not part of the name of control
sequences. Depending on the current value of \escapechar you will see
different things here.

What you need to remember that the way LaTeX works for environments is
that when you type

\begin{foo}

it looks for a macro which could also be used directly as \foo. As you
are seeing the names, and not the control sequences, this means you need
"begin" and "foo".
--
Joseph Wright