You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature requestNew feature or requestpdfRelated to PDF export or PDF embedding.textRelated to the text category, which is all about text handling, shaping, etc.
There are occasions where text is not meant to be selected or searched for, such as watermarks (see below).
I don't know how easy this is to implement with PDF, but it would be a helpful addition to Typst's already-great featureset.
Use Case
Typst's documentation provides a good example:
#setpage(background: rotate(24deg,
text(18pt, fill: rgb("FFCBC4"))[
*CONFIDENTIAL*
]
))
= Typst's secret plans
In the year 2023, we plan to take
over the world (of typesetting).
Reacted by Tv, srestegosaurio, Lina Blume, Bastien Voirin, Victor L., Justus Rossmeier, Davide Zanin, Kyle Huggins, Brad Dixon, Jakub Mańczak and 9 more
I think there are two ways for implementing this feature:
One is to add a flag in text element to indicate that when are exporting to pdf, we do not write the text but rather transform the glyph into an outline shape and write to the pdf. This way the text will be non selectable. A possible interface could be #text(selectable : false, aaa)
The second way is to utilize the ReplacementText feature (sec 14.9.4 PDF 1.7), it would be able to specify a different string when selected. For example, a possible interface would be #text(replacement: "bbb", aaa) and the result rendering would be aaa, but when select and copied out we will have bbb. The latex package called accsupp implemented this feature. In the second approach the non selectable text can be achieved by setting the replacement to be an empty string, such as #text(replacement: "", aaa)
I personally think the second approach would be a more general design, its only drawback being that it requires the pdf reader to support the replacement feature (though I assume most of popular pdf reader should already support). What do you think?
Reacted by Nicolai Weitkemper, Ludwig Austermann, Vilém Zouhar, David Apagyi, srestegosaurio, M. Willis Monroe, lordkekz, Leon Müller and Savio Mak
Thank you for your detailed answer! I'd also prefer the second approach.
For the future (from my understanding, this is not currently a feature), we'd also need a way to control whether text from a SVG should be selectable, so it would make sense to consider both aspects when making a design decision. There's an issue for this latter part already: #1239.
The second approach or something similar to that is definitely preferrable. Outlining the glyphs will make it look different from other text because text rendering is somewhat platform-specific.
Hi I just tried out the text replacement approach. Good news is that it actually works (and the current pdf-writer we are using support it so we do not need PRs on pdf-writer), the bad news is that only seems to be working in acrobat reader, but not in chrome, apple preview, etc. The feature is not widely supported, which is not what I expected.
if you search with bbb, you will find it corresponding to aaa.
However, I've tested with chrome and apple preview, where the feature is not supported (meaning you can still select the aaa and copied it out, and we can search aaa successfully but cannot find bbb).
I also tried with the case of setting the replacement text to be a null empty string. It also works in acrobat but not in the other pdf readers .
So the situation kind of makes me frustrated. I find this link about the accsupp latex package, which said that the accessibility features (including the ActualText we are talking) is not really supported by the many popular PDF readers.
How should we proceed about this issue (supporting non selectable text)? Convert glyphs to shapes can do the job, but then that is not a good idea in terms of the rendering result; My idea is that that if converting to shapes is the only way, then perhaps we should not consider supporting it.
Getting garbage values is a lot easier than that actually. You just need to not write a /ToUnicode mapping, which is separate from the font. But as far as I understood, the desired feature was to make text non-selectable, not make it selectable but garbage when copy-pasted.
Without the /ToUnicode mapping, it will be garbage by default. Of course there are ways to reconstruct it, but if it is displayed, you can reconstruct it with OCR anyways.
It depends on how you write the PDF. The PDFs Typst writes would be garbage by default because we use character id to glyph id identity encoding. If you write ASCII with PDFDocEncoding then it will work.
One is to add a flag in text element to indicate that when are exporting to pdf, we do not write the text but rather transform the glyph into an outline shape and write to the pdf. This way the text will be non selectable. A possible interface could be #text(selectable : false, aaa)
This one would be easy to implement, work universally, result in sub-par text rendering, and be in flagrant violation of PDF/A and PDF/UA.
The second way is to utilize the ReplacementText feature (sec 14.9.4 PDF 1.7), it would be able to specify a different string when selected. For example, a possible interface would be #text(replacement: "bbb", aaa) and the result rendering would be aaa, but when select and copied out we will have bbb. The latex package called accsupp implemented this feature. In the second approach the non selectable text can be achieved by setting the replacement to be an empty string, such as #text(replacement: "", aaa)
Does not work in some readers. Violates 6.8.7 of PDF/A-1a.
Fonts that do not correctly to Unicode are not a good idea. The only viable approaches are tagged PDF as an artifact (not universally supported) and outlining the glyphs (not accessible). I think we should have more specific elements for watermark etc. that just have the right UX in viewers. Also makes HTML export easier.
I have a habit of putting a whole-page sized rotated "draft" watermark on things, and having the watermark text selectable is annoying because for some reason mouse selection prefers the watermark over the body text. This would be very useful.
Reacted by Juan Martín Seery, Sylvan Franklin, ilesoft, abitofathinker, Kanashimia, Jakub Mańczak, Bastien Voirin, Philipp Niedermayer and Eduard Bicego
You make a good point, but I left out some info to make myself sound less petty. I'm in class that makes it purposefully difficult to copy answers into an external document, so I have to screenshot and OCR them. I wanted to give the graders a taste of there own medicine because they are lazy and use autograding software. There are obviously better justifications for this issue like the watermark example.
You make a good point, but I left out some info to make myself sound less petty. I'm in class that makes it purposefully difficult to copy answers into an external document, so I have to screenshot and OCR them. I wanted to give the graders a taste of there own medicine because they are lazy and use autograding software. There are obviously better justifications for this issue like the watermark example.
I have a habit of putting a whole-page sized rotated "draft" watermark on things, and having the watermark text selectable is annoying because for some reason mouse selection prefers the watermark over the body text. This would be very useful.
I wanted to bump this - my boss' feedback when I gave him a typst pdf report I'd made was that it was a pain to review because the "draft" watermark gets selection priority (and also because selecting text that included references selected the sidenote reference as well. Sidenotes are from the tufte-memo template). I confirmed this selection behavior in Acrobat 2024.05.20320.
I love typst! It's awesome! Thanks!
Reacted by Sylvan Franklin, Kirill Lukashev, Florian Obernberger, Max Chang, Brad Dixon, Jakub Mańczak, Saïd Zuhair and Bastien Voirin
I posted about this on the typst forum and was directed here.
I'll give my use-case just for comparison. I'd like to be able to upload my lecture slides for my students but have LLMs struggle to easily ingest the text (I'll provide selectable versions for students with accomodations requiring such). For this use case either non-selectable, or garbage text would work fine.
However, I just tested ChatGPT and NotebookLLM and both of them did not abide by the /ActualText specification mentioned above: #2249 (comment) so in this case non-selectable text would be preferred.
In a pinch I can just use ImageMagick's convert to convert the PDF to PNG and then back to PDF.
Hey I just want to mention that, according from @reknih's comment, one way to achieve the non-selectable text is to use the Artifact tag, but I am a little confused when I dig into it. I tried some way (see a draft implementation in #5938 by introducing a watermark element) and it turns out the Artifact tag might not actually make it non-selectable. I tried with Adobe Acrobat and even it does not support it.
Worried that #5938 might be wrong, I decide to make a small sample PDF first.
Now I include a simple example here that is manually created.
PDF 1.7 14.8.2.2.2 does appear to indicate that the artifact tag used in this way can make text non selectable (or it is recommended to be implemented like this) but in my machine/setup it seems not working for all PDF readers I have.
I wonder does anyone can confirm this using your machine or favouriate PDF readers? (I used free Adobe Acrobat) maybe the paid Adobe Acrobat will support this?
My reasoning is that if the artifact tag appraoch is not working even for Arobat, perhaps we need find new ways to do it?
A sudden idea that comes to my mind is that, can we make the true coordinate of text in one position, and the coordinate of text selection in another position, so that when the user tries to select in the place the text appears to be, the user would not successfully select anything. Does it sound like a good idea?
Second attempt to add set text(selectable: false) in #8902.
This PR only covers page-level text and does not support text in SVGs yet. I'm wondering: do we have a concrete use case for making SVG text unselectable1? It is a lot harder to support for architectural reasons.
Footnotes
It's always possible to achieve this by manually convert the SVG files. ↩
feature requestNew feature or requestpdfRelated to PDF export or PDF embedding.textRelated to the text category, which is all about text handling, shaping, etc.
Activity
[-]Add option to make text non-selectable[/-][+]Add a way to make text non-selectable[/+]LuxxxLucy commentedon Sep 27, 2023
I think there are two ways for implementing this feature:
One is to add a flag in text element to indicate that when are exporting to pdf, we do not write the text but rather transform the glyph into an outline shape and write to the pdf. This way the text will be non selectable. A possible interface could be #text(selectable : false, aaa)
The second way is to utilize the ReplacementText feature (sec 14.9.4 PDF 1.7), it would be able to specify a different string when selected. For example, a possible interface would be #text(replacement: "bbb", aaa) and the result rendering would be aaa, but when select and copied out we will have bbb. The latex package called accsupp implemented this feature. In the second approach the non selectable text can be achieved by setting the replacement to be an empty string, such as #text(replacement: "", aaa)
I personally think the second approach would be a more general design, its only drawback being that it requires the pdf reader to support the replacement feature (though I assume most of popular pdf reader should already support). What do you think?
NicoWeio commentedon Sep 27, 2023
Thank you for your detailed answer! I'd also prefer the second approach.
For the future (from my understanding, this is not currently a feature), we'd also need a way to control whether text from a SVG should be selectable, so it would make sense to consider both aspects when making a design decision. There's an issue for this latter part already: #1239.
laurmaedje commentedon Sep 28, 2023
The second approach or something similar to that is definitely preferrable. Outlining the glyphs will make it look different from other text because text rendering is somewhat platform-specific.
LuxxxLucy commentedon Oct 1, 2023
Hi I just tried out the text replacement approach. Good news is that it actually works (and the current pdf-writer we are using support it so we do not need PRs on pdf-writer), the bad news is that only seems to be working in acrobat reader, but not in chrome, apple preview, etc. The feature is not widely supported, which is not what I expected.
This is a test example. aaabbb.pdf
Essentially this is the normal pdf text block
and this is the one with a ActualText block
If you open it with Adobe acrobat,
However, I've tested with chrome and apple preview, where the feature is not supported (meaning you can still select the aaa and copied it out, and we can search aaa successfully but cannot find bbb).
I also tried with the case of setting the replacement text to be a null empty string. It also works in acrobat but not in the other pdf readers .
So the situation kind of makes me frustrated. I find this link about the accsupp latex package, which said that the accessibility features (including the ActualText we are talking) is not really supported by the many popular PDF readers.
How should we proceed about this issue (supporting non selectable text)? Convert glyphs to shapes can do the job, but then that is not a good idea in terms of the rendering result; My idea is that that if converting to shapes is the only way, then perhaps we should not consider supporting it.
laurmaedje commentedon Oct 12, 2023
Getting garbage values is a lot easier than that actually. You just need to not write a
/ToUnicodemapping, which is separate from the font. But as far as I understood, the desired feature was to make text non-selectable, not make it selectable but garbage when copy-pasted.laurmaedje commentedon Oct 12, 2023
Without the
/ToUnicodemapping, it will be garbage by default. Of course there are ways to reconstruct it, but if it is displayed, you can reconstruct it with OCR anyways.laurmaedje commentedon Oct 12, 2023
It depends on how you write the PDF. The PDFs Typst writes would be garbage by default because we use character id to glyph id identity encoding. If you write ASCII with PDFDocEncoding then it will work.
That aside, @reknih wrote on Discord:
reknih commentedon Oct 12, 2023
To comment on the other approaches:
This one would be easy to implement, work universally, result in sub-par text rendering, and be in flagrant violation of PDF/A and PDF/UA.
Does not work in some readers. Violates 6.8.7 of PDF/A-1a.
Fonts that do not correctly to Unicode are not a good idea. The only viable approaches are tagged PDF as an artifact (not universally supported) and outlining the glyphs (not accessible). I think we should have more specific elements for watermark etc. that just have the right UX in viewers. Also makes HTML export easier.
Kreijstal commentedon Nov 24, 2023
if you export to svg all text is already unselectable, so you can just convert to svg to pdf again, and boom unselectable text
tv42 commentedon Sep 6, 2024
I have a habit of putting a whole-page sized rotated "draft" watermark on things, and having the watermark text selectable is annoying because for some reason mouse selection prefers the watermark over the body text. This would be very useful.
SylvanFranklin commentedon Nov 11, 2024
I also think this would be an awesome feature. I want to make it more annoying for people trying to copy my homework!
Kreijstal commentedon Nov 11, 2024
do people still do this in the age of LLMs?
also they can screenshot it and ask an LLM.
SylvanFranklin commentedon Nov 11, 2024
You make a good point, but I left out some info to make myself sound less petty. I'm in class that makes it purposefully difficult to copy answers into an external document, so I have to screenshot and OCR them. I wanted to give the graders a taste of there own medicine because they are lazy and use autograding software. There are obviously better justifications for this issue like the watermark example.
Kreijstal commentedon Nov 11, 2024
based
abitofathinker commentedon Jan 16, 2025
I wanted to bump this - my boss' feedback when I gave him a typst pdf report I'd made was that it was a pain to review because the "draft" watermark gets selection priority (and also because selecting text that included references selected the sidenote reference as well. Sidenotes are from the tufte-memo template). I confirmed this selection behavior in Acrobat 2024.05.20320.
I love typst! It's awesome! Thanks!
willismonroe commentedon Jan 31, 2025
I posted about this on the typst forum and was directed here.
I'll give my use-case just for comparison. I'd like to be able to upload my lecture slides for my students but have LLMs struggle to easily ingest the text (I'll provide selectable versions for students with accomodations requiring such). For this use case either non-selectable, or garbage text would work fine.
However, I just tested ChatGPT and NotebookLLM and both of them did not abide by the
/ActualTextspecification mentioned above: #2249 (comment) so in this case non-selectable text would be preferred.In a pinch I can just use ImageMagick's
convertto convert the PDF to PNG and then back to PDF.LuxxxLucy commentedon Feb 23, 2025
Hey I just want to mention that, according from @reknih's comment, one way to achieve the non-selectable text is to use the Artifact tag, but I am a little confused when I dig into it. I tried some way (see a draft implementation in #5938 by introducing a watermark element) and it turns out the Artifact tag might not actually make it non-selectable. I tried with Adobe Acrobat and even it does not support it.
Worried that #5938 might be wrong, I decide to make a small sample PDF first.
Now I include a simple example here that is manually created.
aaa.pdf
where the essential part is
PDF 1.7 14.8.2.2.2 does appear to indicate that the artifact tag used in this way can make text non selectable (or it is recommended to be implemented like this) but in my machine/setup it seems not working for all PDF readers I have.
I wonder does anyone can confirm this using your machine or favouriate PDF readers? (I used free Adobe Acrobat) maybe the paid Adobe Acrobat will support this?
My reasoning is that if the artifact tag appraoch is not working even for Arobat, perhaps we need find new ways to do it?
A sudden idea that comes to my mind is that, can we make the true coordinate of text in one position, and the coordinate of text selection in another position, so that when the user tries to select in the place the text appears to be, the user would not successfully select anything. Does it sound like a good idea?
kmlhpk commentedon Feb 24, 2025
@LuxxxLucy Can confirm SumatraPDF v3.5.2 is still able to select the text
laurmaedje commentedon Sep 23, 2026
For posterity after the closing of #7295: The latest conclusion reached on how to realize this is documented in #7295 (comment).
andylizi commentedon Nov 1, 2026
Second attempt to add
set text(selectable: false)in #8902.This PR only covers page-level text and does not support text in SVGs yet. I'm wondering: do we have a concrete use case for making SVG text unselectable1? It is a lot harder to support for architectural reasons.
Footnotes
It's always possible to achieve this by manually convert the SVG files. ↩