Skip to content

Instantly share code, notes, and snippets.

@trueroad
Last active February 15, 2016 16:40
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 trueroad/41d0024be9eabef668ba to your computer and use it in GitHub Desktop.
Save trueroad/41d0024be9eabef668ba to your computer and use it in GitHub Desktop.
Unicode PDF outline strings sample for plain LuaTeX
% -*- coding:utf-8 -*-
Unicode PDF outline strings sample for plain LuaTeX
Copyright(C) Masamichi Hosoda 2016
下記の 2 環境で動作しました。
This is LuaTeX, Version beta-0.80.0 (TeX Live 2015/Cygwin) (rev 5238) (format=luatex 2015.10.17)
This is LuaTeX, Version beta-0.89.1 (TeX Live 2016/W32TeX/dev) (format=luatex 2016.2.11)
% -*- coding:utf-8 -*-
% Unicode PDF outline strings sample for plain LuaTeX
% Copyright(C) Masamichi Hosoda 2016
\input luatexja.sty
\font\lmr{file:lmroman10-regular.otf:+trep;+tlig} at 10pt %
\lmr
\begingroup
\catcode`\%=12
\directlua{
function UTF16oct(str)
tex.sprint(string.char(0x5c) .. 'detokenize' .. string.char(0x7b))
tex.sprint(string.char(0x5c) .. '376' .. string.char(0x5c) .. '377')
for c in string.utfvalues(str) do
if c < 0x10000 then
tex.sprint(
string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
string.char(0x5c) .. string.char(0x25) .. '03o',
(c / 256), (c % 256)))
else
c = c - 0x10000
local c_hi = c / 1024 + 0xd800
local c_lo = c % 1024 + 0xdc00
tex.sprint(
string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
string.char(0x5c) .. string.char(0x25) .. '03o' ..
string.char(0x5c) .. string.char(0x25) .. '03o' ..
string.char(0x5c) .. string.char(0x25) .. '03o',
(c_hi / 256), (c_hi % 256),
(c_lo / 256), (c_lo % 256)))
end
end
tex.sprint(string.char(0x7d))
end
}
\endgroup
\def\toUTFxvioct#1{\directlua{UTF16oct('\luaescapestring{#1}')}}
\ifnum\luatexversion>84
\def\pdfcatalog{\pdfextension catalog}
\def\pdfdest{\pdfextension dest}
\def\pdfoutline{\pdfextension outline}
\fi
\pdfcatalog{/PageMode /UseOutlines}
\pdfdest name{\toUTFxvioct{AäöüB!}} xyz%
AäöüB!
\vfil
\pdfdest name{\toUTFxvioct{日本語}} xyz%
日本語
\vfil
\pdfdest name{\toUTFxvioct{𠮟🍣☃}} xyz%
𠮟🍣☃
\vfil
\pdfdest name{\toUTFxvioct{A B}} xyz%
A B
\vfil
\pdfdest name{\toUTFxvioct{\detokenize{\TeX}}} xyz%
\TeX
\eject
以下、しおり作成用
\pdfoutline goto name{\toUTFxvioct{AäöüB!}} {\toUTFxvioct{AäöüB!}}%
\pdfoutline goto name{\toUTFxvioct{日本語}} {\toUTFxvioct{日本語}}%
\pdfoutline goto name{\toUTFxvioct{𠮟🍣☃}} {\toUTFxvioct{𠮟🍣☃}}%
\pdfoutline goto name{\toUTFxvioct{A B}} {\toUTFxvioct{A B}}%
\pdfoutline goto name{\toUTFxvioct{\detokenize{\TeX}}} {\toUTFxvioct{\detokenize{\TeX}}}%
\bye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment