2

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

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

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
    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 file.tex

ok it all wont work :(

  • 2
    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 07: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 07:52
  • in that case it should be a duplicate of the linked question. If you have something that does not work, make an example document that someone can debug. – David Carlisle Apr 19 '19 at 07:54
  • why are you using \fontsize{1cm}{0cm} ??? – David Carlisle Apr 19 '19 at 07:55
  • Because that is how I want the text to be displayed (the text that should be uncopyable). – hiddenhospitalresearch Apr 19 '19 at 07:59
  • but specifying a baseline-to-baseline space less than the font size is specifying an unachievable constraint so it will be ignored and fall back on its error recovery of using \lineskip spacing so the lines of text will be inconsistently spaced, with the space between baselines depending on the text within each line. – David Carlisle Apr 19 '19 at 08:05
  • oh well I'm not extremely into LaTeX – hiddenhospitalresearch Apr 19 '19 at 08:08
  • 3
    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 08:10

0 Answers0