Last active
February 1, 2025 12:26
-
-
Save k16shikano/bae52171f536cc9496c4112f592b6cf9 to your computer and use it in GitHub Desktop.
コマンドの「前」の文字をみて挙動を変える(LuaTeX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{luacode} | |
\usepackage{luatexbase} | |
\newattribute\inlineattr | |
\newcommand{\inlinestart}{\kern0pt\setattribute{\inlineattr}{100}\kern0pt} | |
\newcommand{\inlineend}{\kern0pt\setattribute{\inlineattr}{101}\kern0pt} | |
\newcommand{\myinlinecmd}[1]{\inlinestart#1\inlineend} | |
\begin{luacode*} | |
local inlineattr = luatexbase.attributes['inlineattr'] | |
function adjust_inline_spacing(head) | |
for item in node.traverse_id(node.id("kern"), head) do | |
local attr = node.has_attribute(item, inlineattr) | |
if attr == 100 then | |
-- print(item.prev.prev.char) | |
if node.id("glyph") == item.prev.prev.id and item.prev.prev.char == 40 then -- "(" | |
print(item.prev.id) | |
local gluenode = node.new(node.id("glue")) | |
gluenode.width = 655360 | |
node.insert_after(head, item, gluenode) | |
end | |
end | |
end | |
return head | |
end | |
luatexbase.add_to_callback("pre_linebreak_filter", adjust_inline_spacing, "adjust_inline_spacing") | |
\end{luacode*} | |
\begin{document} | |
(\myinlinecmd{xxx}) \myinlinecmd{yyy}\ \myinlinecmd{zzz} %=> 「( xxx) yyy zzz」 | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment