Editing Changing the font for a script

From LuaTeXWiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 4: Line 4:
  
 
It is intended just for small chunks of text (a proper noun, a few words, etc.). For proper bidi writing, see typo-dha.lua, typo-dua.lua, typo-dub.lua and typo-duc.lua in context.
 
It is intended just for small chunks of text (a proper noun, a few words, etc.). For proper bidi writing, see typo-dha.lua, typo-dua.lua, typo-dub.lua and typo-duc.lua in context.
 
You may also want to readjust the vertical positioning (the baselines don't always match). This part resorts to a pdf literal and it's commented out (because it's a hack - the glyphs are moved, but the corresponding boxes are not).
 
 
As an alternative approach, you may use combo fonts (provided by luaotfload 2.7).
 
  
 
<pre>
 
<pre>
Line 14: Line 10:
 
\directlua{
 
\directlua{
 
local DIR = node.id("dir")
 
local DIR = node.id("dir")
function arabic_text (head)
+
function show_nodes (head)
  local prevglyf = nil
 
 
   local isArab = false
 
   local isArab = false
 
   for item in node.traverse_id(node.id"glyph", head) do
 
   for item in node.traverse_id(node.id"glyph", head) do
Line 22: Line 17:
 
       if isArab == false then  
 
       if isArab == false then  
 
         isArab = true
 
         isArab = true
         local d = node.new(DIR)
+
         d = node.new(DIR)
 
         d.dir = '+TRT'
 
         d.dir = '+TRT'
         node.insert_before(head, item, d)
+
         node.insert_before(head, item, d)      
        % local r = node.new(node.id'whatsit', node.subtype'pdf_literal')
 
        % r.data = '2 Ts'
 
        % node.insert_before(head, item, r) 
 
 
       end
 
       end
 
     else
 
     else
 
       if isArab == true then
 
       if isArab == true then
 
         isArab = false
 
         isArab = false
         local d = node.new(DIR)
+
         d = node.new(DIR)
 
         d.dir = '-TRT'
 
         d.dir = '-TRT'
         node.insert_before(head, prevglyf, d)
+
         node.insert_after(head, prevglyf, d)
        % local r = node.new(node.id'whatsit', node.subtype'pdf_literal')
 
        % r.data = '0 Ts'
 
        % node.insert_before(head, item, r) 
 
 
       end
 
       end
 
     end
 
     end
Line 44: Line 33:
 
   return head
 
   return head
 
end
 
end
luatexbase.add_to_callback("pre_linebreak_filter", arabic_text, "Arabic text")
+
luatexbase.add_to_callback("pre_linebreak_filter", show_nodes, 'desc')
luatexbase.add_to_callback("hpack_filter", arabic_text, "Arabic text")
+
luatexbase.add_to_callback("hpack_filter", show_nodes, 'desc')
 
}
 
}
  
 
% The contextual analysis for arabic must be after the font
 
% The contextual analysis for arabic must be after the font
% is changed. If fontspec is loaded before, then the callbacks must be
+
% changes. It fontspec is loaded before, then the callbacks must be
 
% reorderer, which is feasible.
 
% reorderer, which is feasible.
  
Line 64: Line 53:
 
\begin{tabular}{rr}
 
\begin{tabular}{rr}
 
One & Two \\
 
One & Two \\
Three & أربعة % :-/ Extra space
+
Three & أربعة % :-/ Estra space
 
\end{tabular}
 
\end{tabular}
  

Please note that all contributions to LuaTeXWiki are considered to be released under the GNU Free Documentation License 1.3 (see LuaTeXWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)