<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.luatex.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Halfb1t</id>
	<title>LuaTeXWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.luatex.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Halfb1t"/>
	<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php/Special:Contributions/Halfb1t"/>
	<updated>2026-05-03T04:16:19Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=Process_input_buffer&amp;diff=169</id>
		<title>Process input buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Process_input_buffer&amp;diff=169"/>
		<updated>2012-11-03T18:16:05Z</updated>

		<summary type="html">&lt;p&gt;Halfb1t: /* TeX as a lightweight markup language */ they ... character --&amp;gt; they ... characters&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Syntax =&lt;br /&gt;
&lt;br /&gt;
This [[Callbacks|callback]] is called whenever TeX needs a new input line from the file it is currently reading. The argument passed to the function registered there is a string representing the original input line; the function should return another string, to be processed by TeX, or &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt;; in the latter case, the original string is processed. So the function should be defined according to the following blueprint:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function (&amp;lt;string&amp;gt; original_line)&lt;br /&gt;
  return &amp;lt;string&amp;gt; adjusted_line or nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case TeX isn&amp;#039;t reading the main document but a file that is &amp;lt;tt&amp;gt;\input&amp;lt;/tt&amp;gt; in it, the callback is called after the &amp;lt;tt&amp;gt;reader&amp;lt;/tt&amp;gt; function possibly defined in the &amp;lt;tt&amp;gt;[[open_read_file]]&amp;lt;/tt&amp;gt; callback.&lt;br /&gt;
&lt;br /&gt;
The following examples aren&amp;#039;t mutually exclusive; however, if one wanted to register them all in the same callback, special care would be needed, as explained [[Callbacks#Several_functions_in_a_callback|in the main page on callbacks]]. Here each call to &amp;lt;tt&amp;gt;callback.register()&amp;lt;/tt&amp;gt; removes whatever there might have been in the callback beforehand.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
&lt;br /&gt;
== Encoding ==&lt;br /&gt;
&lt;br /&gt;
LuaTeX understands UTF-8 and UTF-8 only (ASCII is a part of it, however). A line containing invalid characters will produce an error message: &amp;lt;em&amp;gt;String contains an invalid utf-8 sequence.&amp;lt;/em&amp;gt; Thus documents with different encoding must be converted, and this can be done in &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that such a conversion might not produce anything meaningful when the document is compiled, because the fonts used must have the proper glyphs in the right place; for instance, the Computer Modern fonts don&amp;#039;t have characters with diacritics, and Latin Modern should be used instead. An alternative solution (quite archaic with LuaTeX) is to define the special characters as active, and to make them create a diacritic. For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\catcode`\é = 13&lt;br /&gt;
\def é{\&amp;#039;e}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Latin-1 ===&lt;br /&gt;
&lt;br /&gt;
Reading a document written in Latin-1 (ISO-8859-1) is relatively straightforward, because the &amp;lt;tt&amp;gt;slnunicode&amp;lt;/tt&amp;gt; library embedded in LuaTeX does the conversion at once.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local utf8_char, byte, gsub = unicode.utf8.char, string.byte, string.gsub&lt;br /&gt;
&lt;br /&gt;
local function convert_char (char)&lt;br /&gt;
  return utf8_char(byte(char))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function convert_line (line)&lt;br /&gt;
  return gsub(line, &amp;quot;.&amp;quot;, convert_char)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
callback.register(&amp;quot;process_input_buffer&amp;quot;, convert_line)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code reads as follows (bottom up): the &amp;lt;tt&amp;gt;convert_line&amp;lt;/tt&amp;gt; function is registered in the &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt; callback; it is passed the original input line as its sole argument, and returns another string, namely that line processed with the &amp;lt;tt&amp;gt;string.gsub()&amp;lt;/tt&amp;gt; function. The latter replaces in a string (the first argument) all the occurrences of a pattern (the second argument) with the outcome of its third argument (for further information on &amp;lt;tt&amp;gt;string.gsub()&amp;lt;/tt&amp;gt; see [http://www.lua.org/manual/5.1/manual.html#pdf-string.gsub the Lua reference manual]).&lt;br /&gt;
&lt;br /&gt;
Here the third argument is a function, &amp;lt;tt&amp;gt;convert_char()&amp;lt;/tt&amp;gt; to which is passed whatever matches the pattern. This pattern matches any character, the dot being a magic character. In &amp;lt;tt&amp;gt;convert_char()&amp;lt;/tt&amp;gt;, the character is first converted to a numerical code (the codepoint in Latin-1, see the [http://www.lua.org/manual/5.1/manual.html#pdf-string.byte description of &amp;lt;tt&amp;gt;string.byte()&amp;lt;/tt&amp;gt;]); the code is passed to &amp;lt;tt&amp;gt;unicode.utf8.char&amp;lt;/tt&amp;gt; which, given a number, returns the associated character in UTF-8, the number being interpreted as a code point in Unicode; since the characters in Latin-1 have the same code points as in Unicode, the conversion is automatic here.&lt;br /&gt;
&lt;br /&gt;
The use of &amp;lt;tt&amp;gt;local&amp;lt;/tt&amp;gt; variables ensures speed, and above all that those variables aren&amp;#039;t defined outside the current chunk, for instance, the current &amp;lt;tt&amp;gt;\directlua&amp;lt;/tt&amp;gt; call or the current Lua file; actually, the code could even be embedded between &amp;lt;tt&amp;gt;do&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;end&amp;lt;/tt&amp;gt; and leave absolutely no trace whatsoever.&lt;br /&gt;
&lt;br /&gt;
=== Other 8-bit encodings ===&lt;br /&gt;
&lt;br /&gt;
When using other 8-bit encoding, the previous code won&amp;#039;t work, because it defaults to Latin-1 only. Then one must convert each character one by one by setting up a table matching each input character with the Unicode value; that value can be passed to unicode.utf8.char to yield the desired character.&lt;br /&gt;
&lt;br /&gt;
For instance, here&amp;#039;s the code needed to process a document encoded in Latin/Greek (ISO-8859-7):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local utf8_char, byte = unicode.utf8.char, string.byte&lt;br /&gt;
&lt;br /&gt;
local LatinGreek_table = {&lt;br /&gt;
  [0] = 0x0000, 0x0001, 0x0002, 0x0003, 0x0004,&lt;br /&gt;
  -- ... 240+ other values...&lt;br /&gt;
  0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
local function convert_char (char)&lt;br /&gt;
  return utf8_char(LatinGreek_table[byte(char)])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function convert_line (line)&lt;br /&gt;
  return gsub(line, &amp;quot;.&amp;quot;, convert_char)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
callback.register(&amp;quot;process_input_buffer&amp;quot;, convert_line)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;convert_line()&amp;lt;/tt&amp;gt; function and call to &amp;lt;tt&amp;gt;callback.register()&amp;lt;/tt&amp;gt; are the same as above. What has changed is &amp;lt;tt&amp;gt;convert_char()&amp;lt;/tt&amp;gt;; the numerical value of the original character is now used as an index in the &amp;lt;tt&amp;gt;LatinGreek_table&amp;lt;/tt&amp;gt;, and the value returned is the corresponding Unicode code point; that number is passed to &amp;lt;tt&amp;gt;unicode.utf8.char&amp;lt;/tt&amp;gt; to produce the character in UTF-8.&lt;br /&gt;
&lt;br /&gt;
The values in the &amp;lt;tt&amp;gt;LatinGreek_table&amp;lt;/tt&amp;gt; are assigned to the right indices because they are declared in a row (here in hexadecimal form by prefixing them with &amp;lt;tt&amp;gt;0x&amp;lt;/tt&amp;gt;). The only index that needs to be specified is 0, because indexing of tables in Lua begins at 1 by default. The table length is 254 plus the value at index 0 (not 255, because there is no such character in Latin/Greek). Each index is a code point in Latin/Greek, and the value is the code point of the same character in Unicode. For instance, lowercase omega in Latin/Greek is 249, at which index one finds 0x03C9, lowercase omega in Unicode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== TeX as a lightweight markup language ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt; can be put to an entirely different use, namely to preprocess input strings using some kind of lightweight markup and turn them into proper TeX.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s suppose one has two control sequences, &amp;lt;tt&amp;gt;\italic&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;\bold&amp;lt;/tt&amp;gt;, taking a single argument; let&amp;#039;s suppose furthermore that one wants to write a sentence like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
This is in /italic/ and this is in *bold*.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to be processed by TeX as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
This is in \italic{italic} and this is in \bold{bold}.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so as to produce: `This is in &amp;lt;em&amp;gt;italic&amp;lt;/em&amp;gt; and this is in &amp;lt;strong&amp;gt;bold&amp;lt;/strong&amp;gt;.&amp;#039; The following code does exactly that (the use of the percent sign and of &amp;lt;tt&amp;gt;\\&amp;lt;/tt&amp;gt; without &amp;lt;tt&amp;gt;\noexpand&amp;lt;/tt&amp;gt; means that this code is either in a Lua file or in the second version of &amp;lt;tt&amp;gt;\luacode&amp;lt;/tt&amp;gt; as defined in [[Writing Lua in TeX#Backslash|Writing Lua in TeX]]; also, this code illustrates the registering of an anonymous function instead of a function variable as in the previous examples):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local gsub = string.gsub&lt;br /&gt;
&lt;br /&gt;
callback.register(&amp;quot;process_input_buffer&amp;quot;,&lt;br /&gt;
  function (str)&lt;br /&gt;
    str = gsub(str, &amp;quot;/(.-)/&amp;quot;, &amp;quot;\\italic{%1}&amp;quot;)&lt;br /&gt;
    str = gsub(str, &amp;quot;%*(.-)%*&amp;quot;, &amp;quot;\\bold{%1}&amp;quot;)&lt;br /&gt;
    return str&lt;br /&gt;
  end)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What happens is that the original string is replaced with successive call to &amp;lt;tt&amp;gt;string.gsub&amp;lt;/tt&amp;gt; (see [http://www.lua.org/manual/5.1/manual.html#pdf-string.gsub the Lua reference manual]), in which the captures in the patterns are replaced with themselves as arguments to the TeX function (the non-capture parts of the patterns are discarded). For instance, &amp;lt;tt&amp;gt;/a word/&amp;lt;/tt&amp;gt; yields &amp;lt;tt&amp;gt;\italic{a word}&amp;lt;/tt&amp;gt;. Note that with &amp;lt;tt&amp;gt;\bold&amp;lt;/tt&amp;gt;, the asterisks in the pattern must be escaped with &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt;, otherwise they would be interpreted as magic characters. The line can then be processed by TeX as usual.&lt;br /&gt;
&lt;br /&gt;
Only pairs of slashes or asterisks in the same line will be interpreted as markup, because lines are processed one by one and nothing is remembered from one line to the next (that can be implemented, but is a bit more complicated and dangerous). Hence, nothing will be in italics in the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
This will /not&lt;br /&gt;
be/ in italic.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, slashes will be read.&lt;br /&gt;
&lt;br /&gt;
One can add an unlimited number of replacements of the input line. For instance, here&amp;#039;s a way to mark sections by rows of &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt;&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  str = gsub(str, &amp;quot;^%s*#%s*(.*)&amp;quot;, &amp;quot;\\section{%1}&amp;quot;)&lt;br /&gt;
  str = gsub(str, &amp;quot;^%s*##%s*(.*)&amp;quot;, &amp;quot;\\subsection{%1}&amp;quot;)&lt;br /&gt;
  str = gsub(str, &amp;quot;^%s*###%s*(.*)&amp;quot;, &amp;quot;\\subsubsection{%1}&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What is recognized as a section header is any line beginning with one, two or three hashes, ignoring space before and after. So one can write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# A section&lt;br /&gt;
  ## A subsection&lt;br /&gt;
    ### A subsubsection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complicated things are possible. However, using the [[open read file]] callback (only with an &amp;lt;tt&amp;gt;\input&amp;lt;/tt&amp;gt; file) is preferable if subtlety is required, because it can read an entire file (or any set of lines) before changing anything. Also, the powerful [http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html LPeg library] (embedded in LuaTeX) can be used instead of the default operations.&lt;br /&gt;
&lt;br /&gt;
Finally, one must note that such manipulations can be dangerous or lead to unwanted results. For instance, a line such as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
... the file should be contained in user/directory/myfiles...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will be processed without slashes and with &amp;lt;em&amp;gt;directory&amp;lt;/em&amp;gt; in italics. Thus, such markup should either be used with files specially tailored for it, or contain ways to be overriden or to protect some text.&lt;/div&gt;</summary>
		<author><name>Halfb1t</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=Process_input_buffer&amp;diff=168</id>
		<title>Process input buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Process_input_buffer&amp;diff=168"/>
		<updated>2012-11-03T18:12:31Z</updated>

		<summary type="html">&lt;p&gt;Halfb1t: /* TeX as a lightweight markup language */ percent sing -&amp;gt; percent sign&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Syntax =&lt;br /&gt;
&lt;br /&gt;
This [[Callbacks|callback]] is called whenever TeX needs a new input line from the file it is currently reading. The argument passed to the function registered there is a string representing the original input line; the function should return another string, to be processed by TeX, or &amp;lt;tt&amp;gt;nil&amp;lt;/tt&amp;gt;; in the latter case, the original string is processed. So the function should be defined according to the following blueprint:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function (&amp;lt;string&amp;gt; original_line)&lt;br /&gt;
  return &amp;lt;string&amp;gt; adjusted_line or nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case TeX isn&amp;#039;t reading the main document but a file that is &amp;lt;tt&amp;gt;\input&amp;lt;/tt&amp;gt; in it, the callback is called after the &amp;lt;tt&amp;gt;reader&amp;lt;/tt&amp;gt; function possibly defined in the &amp;lt;tt&amp;gt;[[open_read_file]]&amp;lt;/tt&amp;gt; callback.&lt;br /&gt;
&lt;br /&gt;
The following examples aren&amp;#039;t mutually exclusive; however, if one wanted to register them all in the same callback, special care would be needed, as explained [[Callbacks#Several_functions_in_a_callback|in the main page on callbacks]]. Here each call to &amp;lt;tt&amp;gt;callback.register()&amp;lt;/tt&amp;gt; removes whatever there might have been in the callback beforehand.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
&lt;br /&gt;
== Encoding ==&lt;br /&gt;
&lt;br /&gt;
LuaTeX understands UTF-8 and UTF-8 only (ASCII is a part of it, however). A line containing invalid characters will produce an error message: &amp;lt;em&amp;gt;String contains an invalid utf-8 sequence.&amp;lt;/em&amp;gt; Thus documents with different encoding must be converted, and this can be done in &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that such a conversion might not produce anything meaningful when the document is compiled, because the fonts used must have the proper glyphs in the right place; for instance, the Computer Modern fonts don&amp;#039;t have characters with diacritics, and Latin Modern should be used instead. An alternative solution (quite archaic with LuaTeX) is to define the special characters as active, and to make them create a diacritic. For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\catcode`\é = 13&lt;br /&gt;
\def é{\&amp;#039;e}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Latin-1 ===&lt;br /&gt;
&lt;br /&gt;
Reading a document written in Latin-1 (ISO-8859-1) is relatively straightforward, because the &amp;lt;tt&amp;gt;slnunicode&amp;lt;/tt&amp;gt; library embedded in LuaTeX does the conversion at once.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local utf8_char, byte, gsub = unicode.utf8.char, string.byte, string.gsub&lt;br /&gt;
&lt;br /&gt;
local function convert_char (char)&lt;br /&gt;
  return utf8_char(byte(char))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function convert_line (line)&lt;br /&gt;
  return gsub(line, &amp;quot;.&amp;quot;, convert_char)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
callback.register(&amp;quot;process_input_buffer&amp;quot;, convert_line)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code reads as follows (bottom up): the &amp;lt;tt&amp;gt;convert_line&amp;lt;/tt&amp;gt; function is registered in the &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt; callback; it is passed the original input line as its sole argument, and returns another string, namely that line processed with the &amp;lt;tt&amp;gt;string.gsub()&amp;lt;/tt&amp;gt; function. The latter replaces in a string (the first argument) all the occurrences of a pattern (the second argument) with the outcome of its third argument (for further information on &amp;lt;tt&amp;gt;string.gsub()&amp;lt;/tt&amp;gt; see [http://www.lua.org/manual/5.1/manual.html#pdf-string.gsub the Lua reference manual]).&lt;br /&gt;
&lt;br /&gt;
Here the third argument is a function, &amp;lt;tt&amp;gt;convert_char()&amp;lt;/tt&amp;gt; to which is passed whatever matches the pattern. This pattern matches any character, the dot being a magic character. In &amp;lt;tt&amp;gt;convert_char()&amp;lt;/tt&amp;gt;, the character is first converted to a numerical code (the codepoint in Latin-1, see the [http://www.lua.org/manual/5.1/manual.html#pdf-string.byte description of &amp;lt;tt&amp;gt;string.byte()&amp;lt;/tt&amp;gt;]); the code is passed to &amp;lt;tt&amp;gt;unicode.utf8.char&amp;lt;/tt&amp;gt; which, given a number, returns the associated character in UTF-8, the number being interpreted as a code point in Unicode; since the characters in Latin-1 have the same code points as in Unicode, the conversion is automatic here.&lt;br /&gt;
&lt;br /&gt;
The use of &amp;lt;tt&amp;gt;local&amp;lt;/tt&amp;gt; variables ensures speed, and above all that those variables aren&amp;#039;t defined outside the current chunk, for instance, the current &amp;lt;tt&amp;gt;\directlua&amp;lt;/tt&amp;gt; call or the current Lua file; actually, the code could even be embedded between &amp;lt;tt&amp;gt;do&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;end&amp;lt;/tt&amp;gt; and leave absolutely no trace whatsoever.&lt;br /&gt;
&lt;br /&gt;
=== Other 8-bit encodings ===&lt;br /&gt;
&lt;br /&gt;
When using other 8-bit encoding, the previous code won&amp;#039;t work, because it defaults to Latin-1 only. Then one must convert each character one by one by setting up a table matching each input character with the Unicode value; that value can be passed to unicode.utf8.char to yield the desired character.&lt;br /&gt;
&lt;br /&gt;
For instance, here&amp;#039;s the code needed to process a document encoded in Latin/Greek (ISO-8859-7):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local utf8_char, byte = unicode.utf8.char, string.byte&lt;br /&gt;
&lt;br /&gt;
local LatinGreek_table = {&lt;br /&gt;
  [0] = 0x0000, 0x0001, 0x0002, 0x0003, 0x0004,&lt;br /&gt;
  -- ... 240+ other values...&lt;br /&gt;
  0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
local function convert_char (char)&lt;br /&gt;
  return utf8_char(LatinGreek_table[byte(char)])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function convert_line (line)&lt;br /&gt;
  return gsub(line, &amp;quot;.&amp;quot;, convert_char)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
callback.register(&amp;quot;process_input_buffer&amp;quot;, convert_line)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;convert_line()&amp;lt;/tt&amp;gt; function and call to &amp;lt;tt&amp;gt;callback.register()&amp;lt;/tt&amp;gt; are the same as above. What has changed is &amp;lt;tt&amp;gt;convert_char()&amp;lt;/tt&amp;gt;; the numerical value of the original character is now used as an index in the &amp;lt;tt&amp;gt;LatinGreek_table&amp;lt;/tt&amp;gt;, and the value returned is the corresponding Unicode code point; that number is passed to &amp;lt;tt&amp;gt;unicode.utf8.char&amp;lt;/tt&amp;gt; to produce the character in UTF-8.&lt;br /&gt;
&lt;br /&gt;
The values in the &amp;lt;tt&amp;gt;LatinGreek_table&amp;lt;/tt&amp;gt; are assigned to the right indices because they are declared in a row (here in hexadecimal form by prefixing them with &amp;lt;tt&amp;gt;0x&amp;lt;/tt&amp;gt;). The only index that needs to be specified is 0, because indexing of tables in Lua begins at 1 by default. The table length is 254 plus the value at index 0 (not 255, because there is no such character in Latin/Greek). Each index is a code point in Latin/Greek, and the value is the code point of the same character in Unicode. For instance, lowercase omega in Latin/Greek is 249, at which index one finds 0x03C9, lowercase omega in Unicode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== TeX as a lightweight markup language ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt; can be put to an entirely different use, namely to preprocess input strings using some kind of lightweight markup and turn them into proper TeX.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s suppose one has two control sequences, &amp;lt;tt&amp;gt;\italic&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;\bold&amp;lt;/tt&amp;gt;, taking a single argument; let&amp;#039;s suppose furthermore that one wants to write a sentence like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
This is in /italic/ and this is in *bold*.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to be processed by TeX as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
This is in \italic{italic} and this is in \bold{bold}.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so as to produce: `This is in &amp;lt;em&amp;gt;italic&amp;lt;/em&amp;gt; and this is in &amp;lt;strong&amp;gt;bold&amp;lt;/strong&amp;gt;.&amp;#039; The following code does exactly that (the use of the percent sign and of &amp;lt;tt&amp;gt;\\&amp;lt;/tt&amp;gt; without &amp;lt;tt&amp;gt;\noexpand&amp;lt;/tt&amp;gt; means that this code is either in a Lua file or in the second version of &amp;lt;tt&amp;gt;\luacode&amp;lt;/tt&amp;gt; as defined in [[Writing Lua in TeX#Backslash|Writing Lua in TeX]]; also, this code illustrates the registering of an anonymous function instead of a function variable as in the previous examples):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local gsub = string.gsub&lt;br /&gt;
&lt;br /&gt;
callback.register(&amp;quot;process_input_buffer&amp;quot;,&lt;br /&gt;
  function (str)&lt;br /&gt;
    str = gsub(str, &amp;quot;/(.-)/&amp;quot;, &amp;quot;\\italic{%1}&amp;quot;)&lt;br /&gt;
    str = gsub(str, &amp;quot;%*(.-)%*&amp;quot;, &amp;quot;\\bold{%1}&amp;quot;)&lt;br /&gt;
    return str&lt;br /&gt;
  end)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What happens is that the original string is replaced with successive call to &amp;lt;tt&amp;gt;string.gsub&amp;lt;/tt&amp;gt; (see [http://www.lua.org/manual/5.1/manual.html#pdf-string.gsub the Lua reference manual]), in which the captures in the patterns are replaced with themselves as arguments to the TeX function (the non-capture parts of the patterns are discarded). For instance, &amp;lt;tt&amp;gt;/a word/&amp;lt;/tt&amp;gt; yields &amp;lt;tt&amp;gt;\italic{a word}&amp;lt;/tt&amp;gt;. Note that with &amp;lt;tt&amp;gt;\bold&amp;lt;/tt&amp;gt;, the asterisks in the pattern must be escaped with &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt;, otherwise they would be interpreted as magic character. The line can then be processed by TeX as usual.&lt;br /&gt;
&lt;br /&gt;
Only pairs of slashes or asterisks in the same line will be interpreted as markup, because lines are processed one by one and nothing is remembered from one line to the next (that can be implemented, but is a bit more complicated and dangerous). Hence, nothing will be in italics in the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
This will /not&lt;br /&gt;
be/ in italic.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, slashes will be read.&lt;br /&gt;
&lt;br /&gt;
One can add an unlimited number of replacements of the input line. For instance, here&amp;#039;s a way to mark sections by rows of &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt;&amp;#039;s:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  str = gsub(str, &amp;quot;^%s*#%s*(.*)&amp;quot;, &amp;quot;\\section{%1}&amp;quot;)&lt;br /&gt;
  str = gsub(str, &amp;quot;^%s*##%s*(.*)&amp;quot;, &amp;quot;\\subsection{%1}&amp;quot;)&lt;br /&gt;
  str = gsub(str, &amp;quot;^%s*###%s*(.*)&amp;quot;, &amp;quot;\\subsubsection{%1}&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What is recognized as a section header is any line beginning with one, two or three hashes, ignoring space before and after. So one can write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# A section&lt;br /&gt;
  ## A subsection&lt;br /&gt;
    ### A subsubsection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complicated things are possible. However, using the [[open read file]] callback (only with an &amp;lt;tt&amp;gt;\input&amp;lt;/tt&amp;gt; file) is preferable if subtlety is required, because it can read an entire file (or any set of lines) before changing anything. Also, the powerful [http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html LPeg library] (embedded in LuaTeX) can be used instead of the default operations.&lt;br /&gt;
&lt;br /&gt;
Finally, one must note that such manipulations can be dangerous or lead to unwanted results. For instance, a line such as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
... the file should be contained in user/directory/myfiles...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will be processed without slashes and with &amp;lt;em&amp;gt;directory&amp;lt;/em&amp;gt; in italics. Thus, such markup should either be used with files specially tailored for it, or contain ways to be overriden or to protect some text.&lt;/div&gt;</summary>
		<author><name>Halfb1t</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=Main_Page&amp;diff=167</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Main_Page&amp;diff=167"/>
		<updated>2012-11-03T18:02:58Z</updated>

		<summary type="html">&lt;p&gt;Halfb1t: usefull -&amp;gt; useful&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Welcome to the LuaTeX wiki ==&lt;br /&gt;
&lt;br /&gt;
This is a wiki for [http://www.luatex.org LuaTeX], a typesetting engine derived from &lt;br /&gt;
[http://en.wikipedia.org/wiki/TeX TeX] that includes [http://www.lua.org Lua] as an embedded scripting language.&lt;br /&gt;
&lt;br /&gt;
See [[Special:Allpages|all the articles]] or the [[Special:Recentchanges|recent changes]].&lt;br /&gt;
&lt;br /&gt;
* [http://www.mediawiki.org/wiki/Help:Formatting How to edit wiki pages]&lt;br /&gt;
* [[Bug tracking|Bug tracking]]: Mantis [http://tracker.luatex.org bug tracker]&lt;br /&gt;
&lt;br /&gt;
== Some articles ==&lt;br /&gt;
&lt;br /&gt;
* [[Documentation and help]] points to other online resources (manuals, mailing list, etc.) related to LuaTeX.&lt;br /&gt;
* [[Writing Lua in TeX]] explains how to write Lua code in a TeX document (and back).&lt;br /&gt;
* [[Attributes]] introduces LuaTeX&amp;#039;s thrilling new concept.&lt;br /&gt;
* Pages on callbacks:&lt;br /&gt;
** [[Callbacks]] introduces callbacks and how to use them.&lt;br /&gt;
** There is a page on the [[Post linebreak filter|&amp;lt;tt&amp;gt;post_linebreak_filter&amp;lt;/tt&amp;gt;]] callback, explaining and illustrating it with a couple of examples. The [[Show the hyphenation points]] article is another example of use.&lt;br /&gt;
** The page on [[process input buffer|the &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt; callback]] illustrates how to read documents with non-UTF-8 encoding, and how to write TeX with lightweight markup instead of the usual commands.&lt;br /&gt;
** Another callback is [[show error hook|&amp;lt;tt&amp;gt;show_error_hook&amp;lt;/tt&amp;gt;]], which lets you enliven your error messages!&lt;br /&gt;
** You can fake XeTeX&amp;#039;s interchar tokens with the [[token filter|&amp;lt;tt&amp;gt;token_filter&amp;lt;/tt&amp;gt;]].&lt;br /&gt;
* [[TeX without TeX]] is about using TeX&amp;#039;s functionality (typesetting, pdf writing) only using Lua code (no &amp;lt;tt&amp;gt;\TeX&amp;lt;/tt&amp;gt; macros).&lt;br /&gt;
* [[fontsampler|Create a fontsampler]] using plain LuaTeX and &amp;lt;tt&amp;gt;luaotfload&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* [[Annotate math expressions]] in PDF with a bounding box using LuaLaTeX.&lt;br /&gt;
&lt;br /&gt;
== Packages on LuaTeX ==&lt;br /&gt;
&lt;br /&gt;
* [http://ctan.org/pkg/lua-visual-debug lua-visual-debug] Visual debugging with LuaLaTeX.&lt;br /&gt;
* [https://github.com/koppor/luabibentry luabibentry] Repeat BibTeX entries in a LuaLaTeX document body.&lt;br /&gt;
* [http://ctan.org/pkg/luacode luacode] Helper for executing lua code from within TeX.&lt;br /&gt;
* [http://en.sourceforge.jp/projects/luatex-ja/ LuaTeX-ja] LuaTeX-ja is a macro package to typeset Japanese(also Chinese) texts using Lua(La)TeX.&lt;br /&gt;
* [http://ctan.org/pkg/luaindex luaindex] Create index using lualatex.&lt;br /&gt;
* [http://ctan.org/pkg/luainputenc luainputenc] Replacing inputenc for use in LuaTeX.&lt;br /&gt;
* [http://ctan.org/pkg/lualatex-math lualatex-math] Fixes for mathematics-related LuaLaTeX issues.&lt;br /&gt;
* [http://ctan.org/pkg/lualibs lualibs] Additional Lua functions for LuaTeX macro programmers.&lt;br /&gt;
* [http://ctan.org/pkg/luamplib luamplib] Use LuaTeX&amp;#039;s built-in MetaPost interpreter.&lt;br /&gt;
* [http://ctan.org/pkg/luaotfload luaotfload] OpenType layout system for Plain TeX and LaTeX.&lt;br /&gt;
* [http://ctan.org/pkg/luasseq luasseq] Drawing spectral sequences in LuaLaTeX.&lt;br /&gt;
* [http://ctan.org/pkg/luatexbase luatexbase] Basic resource management for LuaTeX code.&lt;br /&gt;
&lt;br /&gt;
== Useful modules ==&lt;br /&gt;
&lt;br /&gt;
* [https://gist.github.com/556247 viznodelist] LuaTeX nodelist visualization &lt;br /&gt;
&lt;br /&gt;
== From the old bluwiki.com ==&lt;br /&gt;
&lt;br /&gt;
(Mostly by and thanks to [http://omega.enstb.org/yannis/ Yannis Haralambous])&lt;br /&gt;
&lt;br /&gt;
* An example of code [[traversing TeX nodes]] before an horizontal list goes through the line breaking engine;&lt;br /&gt;
* An example of code [[traversing tokens]] just before execution or expansion;&lt;br /&gt;
* you want to [[explore the table obtained from a TrueType font]], loaded by &amp;lt;tt&amp;gt;font.read_ttf&amp;lt;/tt&amp;gt;;&lt;br /&gt;
* you want to [[explore the internal font table]] of a pre-loaded font or of a font you have loaded by &amp;lt;tt&amp;gt;\font&amp;lt;/tt&amp;gt; and then used for at least one glyph;&lt;br /&gt;
* how to [[use a TrueType font]] without going through a TFM or a OFM file;&lt;br /&gt;
* how to do &amp;lt;i&amp;gt;kinsoku&amp;lt;/i&amp;gt; ([[Japanese and more generally CJK typesetting]]);&lt;br /&gt;
* you want a newline in your log file or on the terminal? add &amp;lt;tt&amp;gt;\string\n&amp;lt;/tt&amp;gt; to your string;&lt;br /&gt;
* you want to [[sort a token list]];&lt;br /&gt;
* you want to [[split a comma-separated list]];&lt;br /&gt;
* you want to [[encrypt your document using ROT13]];&lt;br /&gt;
* you want to [[typeset non-TeX files by converting them using Lua code]];&lt;br /&gt;
* example code to [[mirror characters with Bidi_Mirrored property]];&lt;br /&gt;
* using mplib to write [[metapost with LuaTeX]]&lt;/div&gt;</summary>
		<author><name>Halfb1t</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=Main_Page&amp;diff=166</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Main_Page&amp;diff=166"/>
		<updated>2012-11-03T01:27:24Z</updated>

		<summary type="html">&lt;p&gt;Halfb1t: /* Packages on LuaTeX */ Removed * [http://ctan.org/pkg/luapersian luapersian] Persian for LaTeX in LuaTeX.  Deleted from CTAN at author&amp;#039;s request according to Rainer Schöpf, 2012.10.1.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Welcome to the LuaTeX wiki ==&lt;br /&gt;
&lt;br /&gt;
This is a wiki for [http://www.luatex.org LuaTeX], a typesetting engine derived from &lt;br /&gt;
[http://en.wikipedia.org/wiki/TeX TeX] that includes [http://www.lua.org Lua] as an embedded scripting language.&lt;br /&gt;
&lt;br /&gt;
See [[Special:Allpages|all the articles]] or the [[Special:Recentchanges|recent changes]].&lt;br /&gt;
&lt;br /&gt;
* [http://www.mediawiki.org/wiki/Help:Formatting How to edit wiki pages]&lt;br /&gt;
* [[Bug tracking|Bug tracking]]: Mantis [http://tracker.luatex.org bug tracker]&lt;br /&gt;
&lt;br /&gt;
== Some articles ==&lt;br /&gt;
&lt;br /&gt;
* [[Documentation and help]] points to other online resources (manuals, mailing list, etc.) related to LuaTeX.&lt;br /&gt;
* [[Writing Lua in TeX]] explains how to write Lua code in a TeX document (and back).&lt;br /&gt;
* [[Attributes]] introduces LuaTeX&amp;#039;s thrilling new concept.&lt;br /&gt;
* Pages on callbacks:&lt;br /&gt;
** [[Callbacks]] introduces callbacks and how to use them.&lt;br /&gt;
** There is a page on the [[Post linebreak filter|&amp;lt;tt&amp;gt;post_linebreak_filter&amp;lt;/tt&amp;gt;]] callback, explaining and illustrating it with a couple of examples. The [[Show the hyphenation points]] article is another example of use.&lt;br /&gt;
** The page on [[process input buffer|the &amp;lt;tt&amp;gt;process_input_buffer&amp;lt;/tt&amp;gt; callback]] illustrates how to read documents with non-UTF-8 encoding, and how to write TeX with lightweight markup instead of the usual commands.&lt;br /&gt;
** Another callback is [[show error hook|&amp;lt;tt&amp;gt;show_error_hook&amp;lt;/tt&amp;gt;]], which lets you enliven your error messages!&lt;br /&gt;
** You can fake XeTeX&amp;#039;s interchar tokens with the [[token filter|&amp;lt;tt&amp;gt;token_filter&amp;lt;/tt&amp;gt;]].&lt;br /&gt;
* [[TeX without TeX]] is about using TeX&amp;#039;s functionality (typesetting, pdf writing) only using Lua code (no &amp;lt;tt&amp;gt;\TeX&amp;lt;/tt&amp;gt; macros).&lt;br /&gt;
* [[fontsampler|Create a fontsampler]] using plain LuaTeX and &amp;lt;tt&amp;gt;luaotfload&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* [[Annotate math expressions]] in PDF with a bounding box using LuaLaTeX.&lt;br /&gt;
&lt;br /&gt;
== Packages on LuaTeX ==&lt;br /&gt;
&lt;br /&gt;
* [http://ctan.org/pkg/lua-visual-debug lua-visual-debug] Visual debugging with LuaLaTeX.&lt;br /&gt;
* [https://github.com/koppor/luabibentry luabibentry] Repeat BibTeX entries in a LuaLaTeX document body.&lt;br /&gt;
* [http://ctan.org/pkg/luacode luacode] Helper for executing lua code from within TeX.&lt;br /&gt;
* [http://en.sourceforge.jp/projects/luatex-ja/ LuaTeX-ja] LuaTeX-ja is a macro package to typeset Japanese(also Chinese) texts using Lua(La)TeX.&lt;br /&gt;
* [http://ctan.org/pkg/luaindex luaindex] Create index using lualatex.&lt;br /&gt;
* [http://ctan.org/pkg/luainputenc luainputenc] Replacing inputenc for use in LuaTeX.&lt;br /&gt;
* [http://ctan.org/pkg/lualatex-math lualatex-math] Fixes for mathematics-related LuaLaTeX issues.&lt;br /&gt;
* [http://ctan.org/pkg/lualibs lualibs] Additional Lua functions for LuaTeX macro programmers.&lt;br /&gt;
* [http://ctan.org/pkg/luamplib luamplib] Use LuaTeX&amp;#039;s built-in MetaPost interpreter.&lt;br /&gt;
* [http://ctan.org/pkg/luaotfload luaotfload] OpenType layout system for Plain TeX and LaTeX.&lt;br /&gt;
* [http://ctan.org/pkg/luasseq luasseq] Drawing spectral sequences in LuaLaTeX.&lt;br /&gt;
* [http://ctan.org/pkg/luatexbase luatexbase] Basic resource management for LuaTeX code.&lt;br /&gt;
&lt;br /&gt;
== Usefull modules ==&lt;br /&gt;
&lt;br /&gt;
* [https://gist.github.com/556247 viznodelist] LuaTeX nodelist visualization &lt;br /&gt;
&lt;br /&gt;
== From the old bluwiki.com ==&lt;br /&gt;
&lt;br /&gt;
(Mostly by and thanks to [http://omega.enstb.org/yannis/ Yannis Haralambous])&lt;br /&gt;
&lt;br /&gt;
* An example of code [[traversing TeX nodes]] before an horizontal list goes through the line breaking engine;&lt;br /&gt;
* An example of code [[traversing tokens]] just before execution or expansion;&lt;br /&gt;
* you want to [[explore the table obtained from a TrueType font]], loaded by &amp;lt;tt&amp;gt;font.read_ttf&amp;lt;/tt&amp;gt;;&lt;br /&gt;
* you want to [[explore the internal font table]] of a pre-loaded font or of a font you have loaded by &amp;lt;tt&amp;gt;\font&amp;lt;/tt&amp;gt; and then used for at least one glyph;&lt;br /&gt;
* how to [[use a TrueType font]] without going through a TFM or a OFM file;&lt;br /&gt;
* how to do &amp;lt;i&amp;gt;kinsoku&amp;lt;/i&amp;gt; ([[Japanese and more generally CJK typesetting]]);&lt;br /&gt;
* you want a newline in your log file or on the terminal? add &amp;lt;tt&amp;gt;\string\n&amp;lt;/tt&amp;gt; to your string;&lt;br /&gt;
* you want to [[sort a token list]];&lt;br /&gt;
* you want to [[split a comma-separated list]];&lt;br /&gt;
* you want to [[encrypt your document using ROT13]];&lt;br /&gt;
* you want to [[typeset non-TeX files by converting them using Lua code]];&lt;br /&gt;
* example code to [[mirror characters with Bidi_Mirrored property]];&lt;br /&gt;
* using mplib to write [[metapost with LuaTeX]]&lt;/div&gt;</summary>
		<author><name>Halfb1t</name></author>
		
	</entry>
</feed>