Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Last active June 15, 2016 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/2625027 to your computer and use it in GitHub Desktop.
Save zr-tex8r/2625027 to your computer and use it in GitHub Desktop.
LuaLaTeX で bm パッケージが動けばいいね
%
% ixbm.sty
%
%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ixbm}[2016/06/15 v0.3]
\def\ixbm@pkgname{ixbm}
%% preparation
\RequirePackageWithOptions{bm}[2004/02/26]
% environment check
\ifx\directlua\@undefined
\PackageWarning{ixbm}{The engine is not LuaTeX}
\expandafter\endinput\fi\relax
% Lua module
\directlua{ixbm = ixbm or {}}
%--------------------------------------- Allez(1)
\begingroup
\catcode10=12 \endlinechar=10 %
\let\\=\relax \let\%=\@percentchar %
\directlua{
for cc = 0, 255 do
local mcl, mf, mcc = (unpack or table.unpack)(tex.mathcode[cc])
if mcc < 256 then
local mcd = mcl * 0x1000 + mf * 0x100 + mcc
tex.print("\\global\\mathcode"..cc.."="..mcd.." \%")
end
end
}%
\endgroup%
%--------------------------------------- Allez(2)
\begingroup
\let\@@else\else \let\else\relax
\catcode`\"=12
%% check for \mathcode anormaly
\mathcode\z@="1234
\ifdefined\luafunction \ifnum\mathcode\z@="2200034
\global\let\bxMathcodeQuickFix=t
\fi\fi
%% fix for \mathcode anormaly
\ifdefined\bxMathcodeQuickFix
% patch to \bm@test@token
\def\next#1\bm@delimiter\else\bm@mathchar#2\ixbm@nil{%
#1\bm@delimiter\else\ixbm@mathchar##1#2}
\toks@\expandafter\expandafter\expandafter{%
\expandafter\next\bm@test@token{#1}\ixbm@nil}
\edef\next{\gdef\noexpand\bm@test@token##1{\the\toks@}}
\next
% \ixbm@mathchar
\gdef\ixbm@mathchar#1{%
% NB. here the mathcode value cannot be "math-active"
\ifnum`#1<\@cclvi \ifnum\count@>"7FFF
\luafunction\ixbm@correct@mc
\fi\fi
\bm@mathchar}
% Lua stuff
\newluafunction\ixbm@correct@mc
\begingroup
\catcode10=12 \endlinechar=10 %
\let\\=\relax \let\%=\@percentchar %
\directlua{%
lua.get_functions_table()[\the\ixbm@correct@mc] = function()
local mcd, mf, mcl = tex.count["count@"]
mf, mcd = math.floor(mcd / 0x1000000), mcd \% 0x1000000
mcl, mcd = math.floor(mcd / 0x200000), mcd \% 0x200000
if mf < 0x100 and mcl < 8 and mcd < 0x100 then
tex.count["count@"] = mcl * 0x1000 + mf * 0x100 + mcd
end
end}%
\endgroup%
\fi
\endgroup
%------------------- done
\endinput
%% EOF
\documentclass{article}
\usepackage{ixbm}
\begin{document}
\[ (\bm{1},\bm{x}) = 2(\bm{\alpha},\bm{y}) \]
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment