Hide text from displaying but retain it selectable and searchable
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
|
show 4 more comments
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
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 usingevince
. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced bysqp*
? It dosn't work there, althougho
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 runningpdflatex
onABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B
and read by evince is simplyA 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
|
show 4 more comments
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
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
math-mode symbols pdf unicode accsupp
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 usingevince
. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced bysqp*
? It dosn't work there, althougho
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 runningpdflatex
onABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B
and read by evince is simplyA 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
|
show 4 more comments
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 usingevince
. What do you mean by "period... in the symbol"? Do you mean that the period is physically inside the Π, similar to what is produced bysqp*
? It dosn't work there, althougho
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 runningpdflatex
onABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B
and read by evince is simplyA 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
|
show 4 more comments
1 Answer
1
active
oldest
votes
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:
Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.
Use white color for all characters on standard background (or colorize the text with the same color as its background).
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...
- ...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); - ...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"). -- *(Theq
is PDF syntax to save the current graphics state, and theQ
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)):
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.'
Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, withsqp
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.
Use white color for all characters on standard background (or colorize the text with the same color as its background).
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...
- ...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); - ...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"). -- *(Theq
is PDF syntax to save the current graphics state, and theQ
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)):
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.'
Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, withsqp
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
add a comment |
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:
Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.
Use white color for all characters on standard background (or colorize the text with the same color as its background).
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...
- ...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); - ...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"). -- *(Theq
is PDF syntax to save the current graphics state, and theQ
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)):
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.'
Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, withsqp
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
add a comment |
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:
Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.
Use white color for all characters on standard background (or colorize the text with the same color as its background).
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...
- ...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); - ...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"). -- *(Theq
is PDF syntax to save the current graphics state, and theQ
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)):
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.'
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:
Use "text rendering mode 3" (don't strike and don't fill) for the glyph shapes.
Use white color for all characters on standard background (or colorize the text with the same color as its background).
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...
- ...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); - ...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"). -- *(Theq
is PDF syntax to save the current graphics state, and theQ
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)):
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.'
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, withsqp
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
add a comment |
Thank you. Would your solution also work in math mode? Morverover, could you overlay the invisible text with something visible, say, withsqp
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 bysqp*
? It dosn't work there, althougho
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
onABeginAccSupp{method=hex,unicode,ActualText=03A0}$.sqp$EndAccSupp{}B
and read by evince is simplyA 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