Hide text from displaying but retain it selectable and searchable












2














Continuing https://tex.stackexchange.com/a/463516, is there a way to create an invisible PDF text associated with a drawn symbol? Assume that we have some command (say, sqp) which draws some symbol but produces no searchable/selectable text in the PDF. We want to add this textual representation (say, Π, which be neither displayed nor printed) of the drawn symbol to the PDF file such that it would be selectable and searchable. An example of such text is, e.g., Included PDF image has invisible, but selectable text . Reusing @egreg's code from https://tex.stackexchange.com/a/463516/165772 (Thx!), I tried



documentclass{article}
usepackage{amsmath}
usepackage{xparse}
usepackage{accsupp}

ExplSyntaxOn
NewDocumentCommand{sqp}{s}
{
IfBooleanTF{#1}
{
mathord { mathpalette egreg_sqp:Nn { mathrm{o} } }
}
{
mathord {
mathpalette egreg_sqp:Nn { }
}
}
}

box_new:N l__egreg_sqp_temp_box
dim_new:N l__egreg_sqp_wd_dim % width
dim_new:N l__egreg_sqp_ht_dim % height
dim_new:N l__egreg_sqp_th_dim % thickness

cs_new_protected:Nn egreg_sqp:Nn
{% #1 = style declaration, #2 = maybe o
group_begin:
dim_zero:N mathsurround
hbox_set:Nn l__egreg_sqp_temp_box { $#1mathrm{o}$ }
dim_set:Nn l__egreg_sqp_wd_dim { box_wd:N l__egreg_sqp_temp_box }
dim_set:Nn l__egreg_sqp_th_dim { box_wd:N l__egreg_sqp_temp_box/4 }
hbox_set:Nn l__egreg_sqp_temp_box { $#1Pi$ }
dim_set:Nn l__egreg_sqp_ht_dim { box_ht:N l__egreg_sqp_temp_box }

mspace{1mu}
tl_if_empty:nF { #2 }
{
hbox_to_zero:n
{
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { hss $#1#2$ hss }
hss
}
}
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { __egreg_sqp_draw:N #1 hss }
mspace{1mu}
group_end:
}

cs_new_protected:Nn __egreg_sqp_draw:N
{
driver_draw_begin:
driver_draw_moveto:nn { 0pt } { 0pt }
driver_draw_lineto:nn { 0pt } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { 0pt }
driver_draw_closepath:
driver_draw_fill:
driver_draw_end:
}

ExplSyntaxOff

begin{document}
BeginAccSupp{method=hex,unicode,ActualText=03A0}$sqp$EndAccSupp{}
end{document}


In the text layer, this does not produce Π (as I would expect), but only 1 for the end of document.
(An ocg-based solution, as opposed to the accsup-based solution, would probably require a fresh id on each use of the symbol; I wouldn't know how to generate it automatically, and it doesn't seem to produce selectable text. Anyway, I have not tried it.)



I'd prefer a solution that works with all three engines {pdf|xe|lua}latex, even if one would have to use the conditionals if.... As noticed by @Raven, making the background white could work (unless you'd overlay the symbol again with something else like an image) -- that's what I would do when I run out of options.










share|improve this question
























  • you need a real glyph, eg a period, in the symbol, then it works (at least with the adobe reader, but not with sumatra which ignores the actualtext setting.)
    – Ulrike Fischer
    Dec 9 at 16:36












  • @UlrikeFischer I'm using evince. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced by sqp*? It dosn't work there, although o is inside the symbol.
    – user49915
    Dec 9 at 16:41












  • I can't say if evince works, try out $.sqp$.
    – Ulrike Fischer
    Dec 9 at 16:42










  • @UlrikeFischer Alas, the text layer produced by running pdflatex on ABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B and read by evince is simply A B 1.
    – user49915
    Dec 9 at 16:44








  • 1




    then you are probably out of luck and your viewer doesn't support it.
    – Ulrike Fischer
    Dec 9 at 17:10
















2














Continuing https://tex.stackexchange.com/a/463516, is there a way to create an invisible PDF text associated with a drawn symbol? Assume that we have some command (say, sqp) which draws some symbol but produces no searchable/selectable text in the PDF. We want to add this textual representation (say, Π, which be neither displayed nor printed) of the drawn symbol to the PDF file such that it would be selectable and searchable. An example of such text is, e.g., Included PDF image has invisible, but selectable text . Reusing @egreg's code from https://tex.stackexchange.com/a/463516/165772 (Thx!), I tried



documentclass{article}
usepackage{amsmath}
usepackage{xparse}
usepackage{accsupp}

ExplSyntaxOn
NewDocumentCommand{sqp}{s}
{
IfBooleanTF{#1}
{
mathord { mathpalette egreg_sqp:Nn { mathrm{o} } }
}
{
mathord {
mathpalette egreg_sqp:Nn { }
}
}
}

box_new:N l__egreg_sqp_temp_box
dim_new:N l__egreg_sqp_wd_dim % width
dim_new:N l__egreg_sqp_ht_dim % height
dim_new:N l__egreg_sqp_th_dim % thickness

cs_new_protected:Nn egreg_sqp:Nn
{% #1 = style declaration, #2 = maybe o
group_begin:
dim_zero:N mathsurround
hbox_set:Nn l__egreg_sqp_temp_box { $#1mathrm{o}$ }
dim_set:Nn l__egreg_sqp_wd_dim { box_wd:N l__egreg_sqp_temp_box }
dim_set:Nn l__egreg_sqp_th_dim { box_wd:N l__egreg_sqp_temp_box/4 }
hbox_set:Nn l__egreg_sqp_temp_box { $#1Pi$ }
dim_set:Nn l__egreg_sqp_ht_dim { box_ht:N l__egreg_sqp_temp_box }

mspace{1mu}
tl_if_empty:nF { #2 }
{
hbox_to_zero:n
{
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { hss $#1#2$ hss }
hss
}
}
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { __egreg_sqp_draw:N #1 hss }
mspace{1mu}
group_end:
}

cs_new_protected:Nn __egreg_sqp_draw:N
{
driver_draw_begin:
driver_draw_moveto:nn { 0pt } { 0pt }
driver_draw_lineto:nn { 0pt } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { 0pt }
driver_draw_closepath:
driver_draw_fill:
driver_draw_end:
}

ExplSyntaxOff

begin{document}
BeginAccSupp{method=hex,unicode,ActualText=03A0}$sqp$EndAccSupp{}
end{document}


In the text layer, this does not produce Π (as I would expect), but only 1 for the end of document.
(An ocg-based solution, as opposed to the accsup-based solution, would probably require a fresh id on each use of the symbol; I wouldn't know how to generate it automatically, and it doesn't seem to produce selectable text. Anyway, I have not tried it.)



I'd prefer a solution that works with all three engines {pdf|xe|lua}latex, even if one would have to use the conditionals if.... As noticed by @Raven, making the background white could work (unless you'd overlay the symbol again with something else like an image) -- that's what I would do when I run out of options.










share|improve this question
























  • you need a real glyph, eg a period, in the symbol, then it works (at least with the adobe reader, but not with sumatra which ignores the actualtext setting.)
    – Ulrike Fischer
    Dec 9 at 16:36












  • @UlrikeFischer I'm using evince. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced by sqp*? It dosn't work there, although o is inside the symbol.
    – user49915
    Dec 9 at 16:41












  • I can't say if evince works, try out $.sqp$.
    – Ulrike Fischer
    Dec 9 at 16:42










  • @UlrikeFischer Alas, the text layer produced by running pdflatex on ABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B and read by evince is simply A B 1.
    – user49915
    Dec 9 at 16:44








  • 1




    then you are probably out of luck and your viewer doesn't support it.
    – Ulrike Fischer
    Dec 9 at 17:10














2












2








2


1





Continuing https://tex.stackexchange.com/a/463516, is there a way to create an invisible PDF text associated with a drawn symbol? Assume that we have some command (say, sqp) which draws some symbol but produces no searchable/selectable text in the PDF. We want to add this textual representation (say, Π, which be neither displayed nor printed) of the drawn symbol to the PDF file such that it would be selectable and searchable. An example of such text is, e.g., Included PDF image has invisible, but selectable text . Reusing @egreg's code from https://tex.stackexchange.com/a/463516/165772 (Thx!), I tried



documentclass{article}
usepackage{amsmath}
usepackage{xparse}
usepackage{accsupp}

ExplSyntaxOn
NewDocumentCommand{sqp}{s}
{
IfBooleanTF{#1}
{
mathord { mathpalette egreg_sqp:Nn { mathrm{o} } }
}
{
mathord {
mathpalette egreg_sqp:Nn { }
}
}
}

box_new:N l__egreg_sqp_temp_box
dim_new:N l__egreg_sqp_wd_dim % width
dim_new:N l__egreg_sqp_ht_dim % height
dim_new:N l__egreg_sqp_th_dim % thickness

cs_new_protected:Nn egreg_sqp:Nn
{% #1 = style declaration, #2 = maybe o
group_begin:
dim_zero:N mathsurround
hbox_set:Nn l__egreg_sqp_temp_box { $#1mathrm{o}$ }
dim_set:Nn l__egreg_sqp_wd_dim { box_wd:N l__egreg_sqp_temp_box }
dim_set:Nn l__egreg_sqp_th_dim { box_wd:N l__egreg_sqp_temp_box/4 }
hbox_set:Nn l__egreg_sqp_temp_box { $#1Pi$ }
dim_set:Nn l__egreg_sqp_ht_dim { box_ht:N l__egreg_sqp_temp_box }

mspace{1mu}
tl_if_empty:nF { #2 }
{
hbox_to_zero:n
{
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { hss $#1#2$ hss }
hss
}
}
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { __egreg_sqp_draw:N #1 hss }
mspace{1mu}
group_end:
}

cs_new_protected:Nn __egreg_sqp_draw:N
{
driver_draw_begin:
driver_draw_moveto:nn { 0pt } { 0pt }
driver_draw_lineto:nn { 0pt } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { 0pt }
driver_draw_closepath:
driver_draw_fill:
driver_draw_end:
}

ExplSyntaxOff

begin{document}
BeginAccSupp{method=hex,unicode,ActualText=03A0}$sqp$EndAccSupp{}
end{document}


In the text layer, this does not produce Π (as I would expect), but only 1 for the end of document.
(An ocg-based solution, as opposed to the accsup-based solution, would probably require a fresh id on each use of the symbol; I wouldn't know how to generate it automatically, and it doesn't seem to produce selectable text. Anyway, I have not tried it.)



I'd prefer a solution that works with all three engines {pdf|xe|lua}latex, even if one would have to use the conditionals if.... As noticed by @Raven, making the background white could work (unless you'd overlay the symbol again with something else like an image) -- that's what I would do when I run out of options.










share|improve this question















Continuing https://tex.stackexchange.com/a/463516, is there a way to create an invisible PDF text associated with a drawn symbol? Assume that we have some command (say, sqp) which draws some symbol but produces no searchable/selectable text in the PDF. We want to add this textual representation (say, Π, which be neither displayed nor printed) of the drawn symbol to the PDF file such that it would be selectable and searchable. An example of such text is, e.g., Included PDF image has invisible, but selectable text . Reusing @egreg's code from https://tex.stackexchange.com/a/463516/165772 (Thx!), I tried



documentclass{article}
usepackage{amsmath}
usepackage{xparse}
usepackage{accsupp}

ExplSyntaxOn
NewDocumentCommand{sqp}{s}
{
IfBooleanTF{#1}
{
mathord { mathpalette egreg_sqp:Nn { mathrm{o} } }
}
{
mathord {
mathpalette egreg_sqp:Nn { }
}
}
}

box_new:N l__egreg_sqp_temp_box
dim_new:N l__egreg_sqp_wd_dim % width
dim_new:N l__egreg_sqp_ht_dim % height
dim_new:N l__egreg_sqp_th_dim % thickness

cs_new_protected:Nn egreg_sqp:Nn
{% #1 = style declaration, #2 = maybe o
group_begin:
dim_zero:N mathsurround
hbox_set:Nn l__egreg_sqp_temp_box { $#1mathrm{o}$ }
dim_set:Nn l__egreg_sqp_wd_dim { box_wd:N l__egreg_sqp_temp_box }
dim_set:Nn l__egreg_sqp_th_dim { box_wd:N l__egreg_sqp_temp_box/4 }
hbox_set:Nn l__egreg_sqp_temp_box { $#1Pi$ }
dim_set:Nn l__egreg_sqp_ht_dim { box_ht:N l__egreg_sqp_temp_box }

mspace{1mu}
tl_if_empty:nF { #2 }
{
hbox_to_zero:n
{
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { hss $#1#2$ hss }
hss
}
}
hbox_to_wd:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { __egreg_sqp_draw:N #1 hss }
mspace{1mu}
group_end:
}

cs_new_protected:Nn __egreg_sqp_draw:N
{
driver_draw_begin:
driver_draw_moveto:nn { 0pt } { 0pt }
driver_draw_lineto:nn { 0pt } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + 2l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { 0pt }
driver_draw_lineto:nn { l__egreg_sqp_wd_dim + l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { l__egreg_sqp_ht_dim - 0.7l__egreg_sqp_th_dim }
driver_draw_lineto:nn { l__egreg_sqp_th_dim } { 0pt }
driver_draw_closepath:
driver_draw_fill:
driver_draw_end:
}

ExplSyntaxOff

begin{document}
BeginAccSupp{method=hex,unicode,ActualText=03A0}$sqp$EndAccSupp{}
end{document}


In the text layer, this does not produce Π (as I would expect), but only 1 for the end of document.
(An ocg-based solution, as opposed to the accsup-based solution, would probably require a fresh id on each use of the symbol; I wouldn't know how to generate it automatically, and it doesn't seem to produce selectable text. Anyway, I have not tried it.)



I'd prefer a solution that works with all three engines {pdf|xe|lua}latex, even if one would have to use the conditionals if.... As noticed by @Raven, making the background white could work (unless you'd overlay the symbol again with something else like an image) -- that's what I would do when I run out of options.







math-mode symbols pdf unicode accsupp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 22 at 2:44









Kurt Pfeifle

2,44421630




2,44421630










asked Dec 9 at 16:04









user49915

48816




48816












  • you need a real glyph, eg a period, in the symbol, then it works (at least with the adobe reader, but not with sumatra which ignores the actualtext setting.)
    – Ulrike Fischer
    Dec 9 at 16:36












  • @UlrikeFischer I'm using evince. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced by sqp*? It dosn't work there, although o is inside the symbol.
    – user49915
    Dec 9 at 16:41












  • I can't say if evince works, try out $.sqp$.
    – Ulrike Fischer
    Dec 9 at 16:42










  • @UlrikeFischer Alas, the text layer produced by running pdflatex on ABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B and read by evince is simply A B 1.
    – user49915
    Dec 9 at 16:44








  • 1




    then you are probably out of luck and your viewer doesn't support it.
    – Ulrike Fischer
    Dec 9 at 17:10


















  • you need a real glyph, eg a period, in the symbol, then it works (at least with the adobe reader, but not with sumatra which ignores the actualtext setting.)
    – Ulrike Fischer
    Dec 9 at 16:36












  • @UlrikeFischer I'm using evince. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced by sqp*? It dosn't work there, although o is inside the symbol.
    – user49915
    Dec 9 at 16:41












  • I can't say if evince works, try out $.sqp$.
    – Ulrike Fischer
    Dec 9 at 16:42










  • @UlrikeFischer Alas, the text layer produced by running pdflatex on ABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B and read by evince is simply A B 1.
    – user49915
    Dec 9 at 16:44








  • 1




    then you are probably out of luck and your viewer doesn't support it.
    – Ulrike Fischer
    Dec 9 at 17:10
















you need a real glyph, eg a period, in the symbol, then it works (at least with the adobe reader, but not with sumatra which ignores the actualtext setting.)
– Ulrike Fischer
Dec 9 at 16:36






you need a real glyph, eg a period, in the symbol, then it works (at least with the adobe reader, but not with sumatra which ignores the actualtext setting.)
– Ulrike Fischer
Dec 9 at 16:36














@UlrikeFischer I'm using evince. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced by sqp*? It dosn't work there, although o is inside the symbol.
– user49915
Dec 9 at 16:41






@UlrikeFischer I'm using evince. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced by sqp*? It dosn't work there, although o is inside the symbol.
– user49915
Dec 9 at 16:41














I can't say if evince works, try out $.sqp$.
– Ulrike Fischer
Dec 9 at 16:42




I can't say if evince works, try out $.sqp$.
– Ulrike Fischer
Dec 9 at 16:42












@UlrikeFischer Alas, the text layer produced by running pdflatex on ABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B and read by evince is simply A B 1.
– user49915
Dec 9 at 16:44






@UlrikeFischer Alas, the text layer produced by running pdflatex on ABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B and read by evince is simply A B 1.
– user49915
Dec 9 at 16:44






1




1




then you are probably out of luck and your viewer doesn't support it.
– Ulrike Fischer
Dec 9 at 17:10




then you are probably out of luck and your viewer doesn't support it.
– Ulrike Fischer
Dec 9 at 17:10










1 Answer
1






active

oldest

votes


















2














In my comments to the OP/question, I proposed three different methods to write text into a PDF which is invisible, but still selectable and searchable:




  1. Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.


  2. Use white color for all characters on standard background (or colorize the text with the same color as its background).


  3. Use the standard text color (black), but print it onto a black background.



Here is an MWE for my first proposal. For now I'll not make one for the other two. The following shows how to use "text rendering mode 3" in order to write invisible (but searchable) text into a PDF and "do it by (more-or-less pure) LaTeX commands".



It makes use of...




  1. ...the pdfliteral command which in general allows to insert raw PDF code into the LaTeX sources which will then be passed into the PDF output generated by pdflatex (not xelatex or lualatex);

  2. ...the PDF code snippet 3 Tr which is PDF syntax in order to set the text rendering mode to 3 (meaning "no stroke and no fill"). -- *(The q is PDF syntax to save the current graphics state, and the Q is for restoring it again to the previous text rendering mode).**


Here is the MWE:




documentclass{article}
begin{document}
This is my normal text.\
makebox[50pt][c]{pdfliteral page{q 3 Tr}This is hidden (but searchable) text.pdfliteral page{Q}}
\This is more normal text.\
end{document}


Compile this into PDF: pdflatex my.tex. Open the PDF in any viewer and select all (try to hit ctrl+a (Windows, Linux) or cmd+a (macOS)):



enter image description here



As you can see, there is something highlighted but not visible in between the two readable sentences. To find out what it is,...




  • ...either run pdftotext -layout my.pdf -,

  • ...or search for the string 'This is hidden (but searchable) text.'


enter image description here






share|improve this answer





















  • Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, with sqp from the OP?
    – user49915
    Dec 23 at 18:21












  • @user49915: Have you considered to find this out by yourself?
    – Kurt Pfeifle
    Dec 23 at 18:50










  • Of course not: even if I solve the first issue, I wouldn't know how to solve the second one.
    – user49915
    Dec 23 at 19:07










  • @user49915: I am sorry that my answer does nothing to help you solve the issue you stated in your OP. For the "second" issue: either extend your OP to clearly state it, or please ask a new question as a separate posting.
    – Kurt Pfeifle
    Dec 23 at 20:22











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f463968%2fhide-text-from-displaying-but-retain-it-selectable-and-searchable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














In my comments to the OP/question, I proposed three different methods to write text into a PDF which is invisible, but still selectable and searchable:




  1. Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.


  2. Use white color for all characters on standard background (or colorize the text with the same color as its background).


  3. Use the standard text color (black), but print it onto a black background.



Here is an MWE for my first proposal. For now I'll not make one for the other two. The following shows how to use "text rendering mode 3" in order to write invisible (but searchable) text into a PDF and "do it by (more-or-less pure) LaTeX commands".



It makes use of...




  1. ...the pdfliteral command which in general allows to insert raw PDF code into the LaTeX sources which will then be passed into the PDF output generated by pdflatex (not xelatex or lualatex);

  2. ...the PDF code snippet 3 Tr which is PDF syntax in order to set the text rendering mode to 3 (meaning "no stroke and no fill"). -- *(The q is PDF syntax to save the current graphics state, and the Q is for restoring it again to the previous text rendering mode).**


Here is the MWE:




documentclass{article}
begin{document}
This is my normal text.\
makebox[50pt][c]{pdfliteral page{q 3 Tr}This is hidden (but searchable) text.pdfliteral page{Q}}
\This is more normal text.\
end{document}


Compile this into PDF: pdflatex my.tex. Open the PDF in any viewer and select all (try to hit ctrl+a (Windows, Linux) or cmd+a (macOS)):



enter image description here



As you can see, there is something highlighted but not visible in between the two readable sentences. To find out what it is,...




  • ...either run pdftotext -layout my.pdf -,

  • ...or search for the string 'This is hidden (but searchable) text.'


enter image description here






share|improve this answer





















  • Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, with sqp from the OP?
    – user49915
    Dec 23 at 18:21












  • @user49915: Have you considered to find this out by yourself?
    – Kurt Pfeifle
    Dec 23 at 18:50










  • Of course not: even if I solve the first issue, I wouldn't know how to solve the second one.
    – user49915
    Dec 23 at 19:07










  • @user49915: I am sorry that my answer does nothing to help you solve the issue you stated in your OP. For the "second" issue: either extend your OP to clearly state it, or please ask a new question as a separate posting.
    – Kurt Pfeifle
    Dec 23 at 20:22
















2














In my comments to the OP/question, I proposed three different methods to write text into a PDF which is invisible, but still selectable and searchable:




  1. Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.


  2. Use white color for all characters on standard background (or colorize the text with the same color as its background).


  3. Use the standard text color (black), but print it onto a black background.



Here is an MWE for my first proposal. For now I'll not make one for the other two. The following shows how to use "text rendering mode 3" in order to write invisible (but searchable) text into a PDF and "do it by (more-or-less pure) LaTeX commands".



It makes use of...




  1. ...the pdfliteral command which in general allows to insert raw PDF code into the LaTeX sources which will then be passed into the PDF output generated by pdflatex (not xelatex or lualatex);

  2. ...the PDF code snippet 3 Tr which is PDF syntax in order to set the text rendering mode to 3 (meaning "no stroke and no fill"). -- *(The q is PDF syntax to save the current graphics state, and the Q is for restoring it again to the previous text rendering mode).**


Here is the MWE:




documentclass{article}
begin{document}
This is my normal text.\
makebox[50pt][c]{pdfliteral page{q 3 Tr}This is hidden (but searchable) text.pdfliteral page{Q}}
\This is more normal text.\
end{document}


Compile this into PDF: pdflatex my.tex. Open the PDF in any viewer and select all (try to hit ctrl+a (Windows, Linux) or cmd+a (macOS)):



enter image description here



As you can see, there is something highlighted but not visible in between the two readable sentences. To find out what it is,...




  • ...either run pdftotext -layout my.pdf -,

  • ...or search for the string 'This is hidden (but searchable) text.'


enter image description here






share|improve this answer





















  • Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, with sqp from the OP?
    – user49915
    Dec 23 at 18:21












  • @user49915: Have you considered to find this out by yourself?
    – Kurt Pfeifle
    Dec 23 at 18:50










  • Of course not: even if I solve the first issue, I wouldn't know how to solve the second one.
    – user49915
    Dec 23 at 19:07










  • @user49915: I am sorry that my answer does nothing to help you solve the issue you stated in your OP. For the "second" issue: either extend your OP to clearly state it, or please ask a new question as a separate posting.
    – Kurt Pfeifle
    Dec 23 at 20:22














2












2








2






In my comments to the OP/question, I proposed three different methods to write text into a PDF which is invisible, but still selectable and searchable:




  1. Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.


  2. Use white color for all characters on standard background (or colorize the text with the same color as its background).


  3. Use the standard text color (black), but print it onto a black background.



Here is an MWE for my first proposal. For now I'll not make one for the other two. The following shows how to use "text rendering mode 3" in order to write invisible (but searchable) text into a PDF and "do it by (more-or-less pure) LaTeX commands".



It makes use of...




  1. ...the pdfliteral command which in general allows to insert raw PDF code into the LaTeX sources which will then be passed into the PDF output generated by pdflatex (not xelatex or lualatex);

  2. ...the PDF code snippet 3 Tr which is PDF syntax in order to set the text rendering mode to 3 (meaning "no stroke and no fill"). -- *(The q is PDF syntax to save the current graphics state, and the Q is for restoring it again to the previous text rendering mode).**


Here is the MWE:




documentclass{article}
begin{document}
This is my normal text.\
makebox[50pt][c]{pdfliteral page{q 3 Tr}This is hidden (but searchable) text.pdfliteral page{Q}}
\This is more normal text.\
end{document}


Compile this into PDF: pdflatex my.tex. Open the PDF in any viewer and select all (try to hit ctrl+a (Windows, Linux) or cmd+a (macOS)):



enter image description here



As you can see, there is something highlighted but not visible in between the two readable sentences. To find out what it is,...




  • ...either run pdftotext -layout my.pdf -,

  • ...or search for the string 'This is hidden (but searchable) text.'


enter image description here






share|improve this answer












In my comments to the OP/question, I proposed three different methods to write text into a PDF which is invisible, but still selectable and searchable:




  1. Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.


  2. Use white color for all characters on standard background (or colorize the text with the same color as its background).


  3. Use the standard text color (black), but print it onto a black background.



Here is an MWE for my first proposal. For now I'll not make one for the other two. The following shows how to use "text rendering mode 3" in order to write invisible (but searchable) text into a PDF and "do it by (more-or-less pure) LaTeX commands".



It makes use of...




  1. ...the pdfliteral command which in general allows to insert raw PDF code into the LaTeX sources which will then be passed into the PDF output generated by pdflatex (not xelatex or lualatex);

  2. ...the PDF code snippet 3 Tr which is PDF syntax in order to set the text rendering mode to 3 (meaning "no stroke and no fill"). -- *(The q is PDF syntax to save the current graphics state, and the Q is for restoring it again to the previous text rendering mode).**


Here is the MWE:




documentclass{article}
begin{document}
This is my normal text.\
makebox[50pt][c]{pdfliteral page{q 3 Tr}This is hidden (but searchable) text.pdfliteral page{Q}}
\This is more normal text.\
end{document}


Compile this into PDF: pdflatex my.tex. Open the PDF in any viewer and select all (try to hit ctrl+a (Windows, Linux) or cmd+a (macOS)):



enter image description here



As you can see, there is something highlighted but not visible in between the two readable sentences. To find out what it is,...




  • ...either run pdftotext -layout my.pdf -,

  • ...or search for the string 'This is hidden (but searchable) text.'


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 22 at 2:42









Kurt Pfeifle

2,44421630




2,44421630












  • Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, with sqp from the OP?
    – user49915
    Dec 23 at 18:21












  • @user49915: Have you considered to find this out by yourself?
    – Kurt Pfeifle
    Dec 23 at 18:50










  • Of course not: even if I solve the first issue, I wouldn't know how to solve the second one.
    – user49915
    Dec 23 at 19:07










  • @user49915: I am sorry that my answer does nothing to help you solve the issue you stated in your OP. For the "second" issue: either extend your OP to clearly state it, or please ask a new question as a separate posting.
    – Kurt Pfeifle
    Dec 23 at 20:22


















  • Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, with sqp from the OP?
    – user49915
    Dec 23 at 18:21












  • @user49915: Have you considered to find this out by yourself?
    – Kurt Pfeifle
    Dec 23 at 18:50










  • Of course not: even if I solve the first issue, I wouldn't know how to solve the second one.
    – user49915
    Dec 23 at 19:07










  • @user49915: I am sorry that my answer does nothing to help you solve the issue you stated in your OP. For the "second" issue: either extend your OP to clearly state it, or please ask a new question as a separate posting.
    – Kurt Pfeifle
    Dec 23 at 20:22
















Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, with sqp from the OP?
– user49915
Dec 23 at 18:21






Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, with sqp from the OP?
– user49915
Dec 23 at 18:21














@user49915: Have you considered to find this out by yourself?
– Kurt Pfeifle
Dec 23 at 18:50




@user49915: Have you considered to find this out by yourself?
– Kurt Pfeifle
Dec 23 at 18:50












Of course not: even if I solve the first issue, I wouldn't know how to solve the second one.
– user49915
Dec 23 at 19:07




Of course not: even if I solve the first issue, I wouldn't know how to solve the second one.
– user49915
Dec 23 at 19:07












@user49915: I am sorry that my answer does nothing to help you solve the issue you stated in your OP. For the "second" issue: either extend your OP to clearly state it, or please ask a new question as a separate posting.
– Kurt Pfeifle
Dec 23 at 20:22




@user49915: I am sorry that my answer does nothing to help you solve the issue you stated in your OP. For the "second" issue: either extend your OP to clearly state it, or please ask a new question as a separate posting.
– Kurt Pfeifle
Dec 23 at 20:22


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f463968%2fhide-text-from-displaying-but-retain-it-selectable-and-searchable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?