4

I would like to create a macro that converts its paramater into an image with the goal that the text within this macro is not found using the search feature built into standard PDF viewers.

Thus, searching the resulting document for "text" should produce only two matches and not four. That is, any text in the highlighted box should ignored.

enter image description here

Use-Case

I generate a large index of files and want to be able to search by the index entry only (and not the files names).

MWE:

\documentclass{article}
\usepackage{tikz}

\tikzset{Node Style/.style={draw=red, thin, fill=yellow!50, anchor=base, inner sep=1pt,}}
\newcommand{\NonSearchableText}[2][]{%
    \tikz[baseline] \node [Node Style, #1] at (0,0) {#2};%
}%

\begin{document}
    \textbf{searchable text}
    \indent\NonSearchableText{non-searchable-text}

    \textbf{searchable text}
    \indent\NonSearchableText{non-searchable-text}
\end{document}

Desired Ouput

The desired output can be created by using the first file here to create the image non-searchable-text.png which is included by the second.

  1. File name: non-searchable-text.tex

    %%% https://tex.stackexchange.com/questions/34054/tex-to-image-over-command-line
    \documentclass[convert={density=300,outext=.png}]{standalone}
    \usepackage{tikz}
    
    \tikzset{Node Style/.style={draw=red, thin, fill=yellow!50, anchor=base, inner sep=1pt,}}
    \newcommand{\NonSearchableText}[2][]{%
        \tikz[baseline] \node [Node Style, #1] at (0,0) {#2};%
    }%
    
    \begin{document}
        \NonSearchableText{non-searchable-text}
    \end{document}
    
  2. Main File:

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage[export]{adjustbox}
    
    %% https://tex.stackexchange.com/questions/98297/create-command-to-inline-an-image-in-a-question
    \newcommand*{\Image}[1]{\includegraphics[valign=m]{#1}}%
    
    \begin{document}
        \textbf{searchable text}
        \indent\Image{non-searchable-text.png}
    
        \textbf{searchable text}
        \indent\Image{non-searchable-text.png}
    \end{document}
    
  • The problem is that a PDF based image (like TikZ) probably includes the text as text In the (vector graphics) image. You would need to produce a rasterized image, which means using a graphics editor to convert. – John Kormylo Nov 5 '18 at 14:01
  • You could precompute rasterized images of each letter. There might be something useful in tex.stackexchange.com/questions/29402/… – John Kormylo Nov 5 '18 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.