1

I have a report where I mention some people. Sometimes I want to hide the real name of these people. I would like to write a macro that converts the name to a single character.

\name{John Doe} should print PersonA when hide boolean is true, and to John Doe otherwise.

I need some macro that converts the name to a single character, but all each name in the document should be converted to the same character.

1 Answer 1

1

I store each name in a property list coupled with a dynamically computed integer represented by letters.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\name}{m}
 {
  \textnik_name:n { #1 }
 }

\NewDocumentCommand{\hidenames}{}
 {
  \bool_gset_false:N \g_textnik_name_bool
 }

\NewDocumentCommand{\shownames}{}
 {
  \bool_gset_true:N \g_textnik_name_bool
 }

\prop_new:N \g_textnik_name_prop
\int_new:N \g_textnik_name_int
\bool_new:N \g_textnik_name_bool

\cs_new_protected:Nn \textnik_name:n
 {
  \prop_if_in:NnF \g_textnik_name_prop { #1 }
   {
    \int_gincr:N \g_textnik_name_int
    \prop_gput:Nnx \g_textnik_name_prop { #1 } { \int_to_Alph:n { \g_textnik_name_int } }
   }
  \bool_if:NTF \g_textnik_name_bool
   {
    #1
   }
   {
    Person\prop_item:Nn \g_textnik_name_prop { #1 }
   }
 }

\ExplSyntaxOff

\shownames

\begin{document}

Here we talk about \name{John Doe} and about
\name{Ööç Galaxy} and again about \name{John Doe}.

\hidenames

Here we talk about \name{John Doe} and about
\name{Ööç Galaxy} and again about \name{John Doe}.

\end{document}

enter image description here

1
  • Thanks. I was only thinking in kind of hash function, and couldn't see this simpler approach.
    – TeXtnik
    Dec 12, 2019 at 7:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .