如何在 LaTeX 课堂中混淆文本

如何在 LaTeX 课堂中混淆文本

我想做类似的事情https://tex.stackexchange.com/a/127902/176093 但是我想要混淆的文本是在一个类中,并且当前定义为\fontsize{1cm}{0cm}\selectfont my text 该类是用 LaTeX 编写的(也可能是 LuaLaTex??)我该怎么做?

例如:file.tex

\documentclass[nosignatures,dvipsnames]{classfile.cls}

\usepackage{acronym}
\usepackage{luatexbase}
\usepackage{luaotfload}
\RequireLuaModule{obfuscate}
\def \packagecmd #1{\directlua {packagedata.#1}}

%% the obfuscate environment, mapping to Lua functions that enable and
%% disable tounicode obfuscation
\def \beginobfuscate {\packagecmd {obfuscate_begin ()}}
\def \endobfuscate   {\packagecmd {obfuscate_end   ()}}

\beginobfuscate

\font \italicfont = "file:Cantarell-Regular.otf:mode=base"
\endobfuscate


\begin{document}
\italicfont
hello
{\italicfont obfuscate please}
\showobfsc
\end{document}

类文件.cls

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{classfile}[26/03/2019 example class]
\renewcommand\normalsize{%
   \@setfontsize\normalsize\@xpt\@xiipt
   \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
   \abovedisplayshortskip \z@ \@plus3\p@
   \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
   \belowdisplayskip \abovedisplayskip
   \let\@listi\@listI}
\usepackage{acronym}
\usepackage{luatexbase}
\usepackage{luaotfload}
\RequireLuaModule{obfuscate}
\def \packagecmd #1{\directlua {packagedata.#1}}

%% the obfuscate environment, mapping to Lua functions that enable and
%% disable tounicode obfuscation
\def \beginobfuscate {\packagecmd {obfuscate_begin ()}}
\def \endobfuscate   {\packagecmd {obfuscate_end   ()}}

\beginobfuscate

\font \italicfont = "file:Cantarell-Regular.otf:mode=base"
\endobfuscate

\newcommand{\showobfsc}{
    {\italicfont\fontsize{1cm}{1cm}\selectfont (this should be obfuscated)}\\[5cm]
}

\endinput

混淆器

packagedata = packagedata or { }

local mathrandom    = math.random
local stringformat  = string.format

--- this is the callback by means of which we will obfuscate
--- the tounicode values so they map to random characters of
--- the printable ascii range (between 0x21 / 33 and 0x7e / 126)

local obfuscate = function (tfmdata, _specification)
  if not tfmdata or type (tfmdata) ~= "table" then
    return
  end

  local characters = tfmdata.characters
  if characters then
    for codepoint, char in next, characters do
      char.tounicode = stringformat ([[%0.4X]], mathrandom (0x21, 0x7e))
    end
  end
end

--- we also need some functions to toggle the callback activation so
--- we can obfuscate fonts selectively

local active = false

packagedata.obfuscate_begin = function ()
  if not active then
    luatexbase.add_to_callback ("luaotfload.patch_font", obfuscate,
                                "user.obfuscate_font", 1)
    active = true
  end
end

packagedata.obfuscate_end = function ()
  if active then
    luatexbase.remove_from_callback ("luaotfload.patch_font",
                                     "user.obfuscate_font")
    active = false
  end
end

lualatex 文件.tex

好吧,一切都行不通 :(

相关内容