# How to obfuscate text in LaTeX class

I want to do something like https://tex.stackexchange.com/a/127902/176093 however the text I want to obfuscate is in a class and currently defined as \fontsize{1cm}{0cm}\selectfont my text the class is written in LaTeX (may be LuaLaTex as wel??) How should I do that?

example: file.tex

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

\usepackage{acronym}
\usepackage{luatexbase}
\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
\showobfsc
\end{document}


classfile.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}
\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


obfuscate.lua

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
"user.obfuscate_font", 1)
active = true
end
end

packagedata.obfuscate_end = function ()
if active then
"user.obfuscate_font")
active = false
end
end


lualatex file.tex

ok it all wont work :(

• Welcome to TeX.SX! With the little amount of information you provided it is really difficult to help you. Have you tried the answer you linked to? If you did, what did not work? – Phelype Oleinik Apr 18 '19 at 20:48
• Well I can use that answer within normal text I store in a tex file, however doing it in a cls file (which is what I think I want, or doing it \fontsize{1cm}{0cm}\selectfont my text doesn't work) – hiddenhospitalresearch Apr 18 '19 at 22:22
• your question is very unclear, \fontsize{1cm}{0cm}\selectfont doesn't obfuscate any text, it just sets large 1cm high text with inconsistent line spacing (as it will fail to achieve the specified 0pt spacing). The answer you link to is about preventing cutting and pasting text from the generated pdf, is that what you mean here or do you mean obscuring the text in the source view of the class file? as always it helps if you provide a complete small test file and say what you want it to do. – David Carlisle Apr 19 '19 at 7:37
• preventing cutting and pasting text from the generated pdf is what I want, however the text that I want to protect is in a class file, I don't care about how it is structured in the source file – hiddenhospitalresearch Apr 19 '19 at 7:52
• you don't need to be that fluent in tex to see that specifying 1cm high text to be set on lines that are 0cm apart is not going to fit. – David Carlisle Apr 19 '19 at 8:10