1

Suppose that you have an existing large document with lots of tikzpictures in it. Is it possible to put some code in the preamble that effectively turn off all text and math within these figures?

(Edit: It would be even better if just math mode content could be turned off, but I assumed that was too much to hope for.)

For background, I'm thinking about processing tikzpictures in a way to separate the graphic part from the text/math part, for eventual use in a web page. I'd process the graphic part of each image into a standalone pdf, and use pdf2svg to create an svg. Then I'd overlay the svg with the text/math using MathJax (to the degree that is possible, since not everything is going to work in MathJax.)

cfr
  • 198,882
alex.jordan
  • 2,179
  • @cfr Because of the accessibility features that MathJax offers. Such a picture with the text and math as an image is not web accessible. A screen reader can't access those things. A user can't manipulate (zoom) the math alone. And it's less important (to me), but a user can't see the input tex for any math content. – alex.jordan Aug 08 '15 at 19:23
  • Also it would allow for the svg portion to be scaled separately from the text parts, so it wouldn't matter if the page dynamically rescaled the svg, while leaving the MathJax consistent in size with the rest of the page. – alex.jordan Aug 08 '15 at 19:28
  • 1
    \tikzset{every node/.append style={text opacity=0}} might get you close, though it doesn't really turn off the text, only makes it transparent. – Torbjørn T. Aug 08 '15 at 21:01
  • @cfr No, hence my posting as comment and saying might get you close. – Torbjørn T. Aug 08 '15 at 21:18
  • @cfr Well, that too. – Torbjørn T. Aug 08 '15 at 21:21
  • @cfr Yes, the graphical part of such an image needs a description in alt text or a caption or the surrounding text. For that, I have work to do. But many of these images have math expressions too, and I'd rather let MathJax provide the MathML to a screen reader than come up with alt text. Also, there is the other reason for this: allowing the width/height of the svg to rescale without affecting the size of the text/math relative to the text/math in the paragraphs surrounding the image. – alex.jordan Aug 08 '15 at 23:23
  • @TorbjørnT. Thanks, I'll give this a try. It might get me far enough. – alex.jordan Aug 08 '15 at 23:23
  • 1
    If you always write your text and mathematics inside a command like \hideable{...}. Then you could put \let\hideable\phantom at the top of your document when you want to hide this material and \let\hideable\text the rest of the time (or something similar if you are not using amsmath). –  Aug 09 '15 at 00:58
  • @Symbol1 It's not a duplicate of that question. My question is not about making external image files. It is about making external image files that omit text and math content. For example, if there were a plot of y=x^2, with the curve labeled "$y=x^2$", I want to produce the image, but omit that label. And I do not want to manually delete the label from the input, because I want to apply this to thousands of images. – alex.jordan Apr 22 '17 at 21:03
  • @alex.jordan Sorry I misunderstand the question. Did Torbjørn T's first comment solves you question? – Symbol 1 Apr 22 '17 at 21:07
  • @Symbol1 It is better than anything else, but there is one main issue. The resulting pdf still "has" the text content, and if the pdf is converted to svg, it is still there as well. So screen reader navigation of the svg will encounter the text. Worse, the current methods for converting pdg to svg turn text into image content, instead of remaining as text which is technically a possibility within svg. So the screen reader encounters the text as a weirdly drawn image. The best would be a way to generate svg with the text intact as text. – alex.jordan Apr 22 '17 at 21:35
  • 1
    @alex.jordan I see your point. I had update my answer a little bit so it is closer to what you dreamed. By the way, it seems like PGF support tex2ht, did you ever try it? – Symbol 1 Apr 22 '17 at 21:55

1 Answers1

1

If you are not using pic, align, nodepart, matrix and any other fancy feature, the following will remove all text in nodes and also print the TeX code to the log file

If you would like to use those feature, you would need to put \phantom in deeper macros, but the idea is the same: \phantom is the easiest (and sometimes the only) way to keep the space that text occupied yet does not output any text into PDF files.

You might want to read tikz.code.tex line 3636-4113 to see how TikZ handles nodes/pic/align/nodepart/matrix.

\documentclass[border=9,tikz]{standalone}
\begin{document}

\makeatletter
\def\tikz@fig@main#1{%
    \message{^^J^^Jnode content:\detokenize{#1}^^J^^J}%
    \tikz@@fig@main\phantom{#1}\egroup%
}

\tikz\node[draw]{normal text};

\tikz\node[draw]{math formula $1+2+4+\cdots+2^n=2^{n+1}-1$};

\end{document}

The PDF is

The .log is

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex 2017.4.5)  22 APR 2017 16:32

... (omitted)

node content:normal text

[1

{/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]

node content:math formula $1+2+4+\cdots +2^n=2^{n+1}-1$

... (omitted)

PDF statistics: 14 PDF objects out of 1000 (max. 8388607) 9 compressed objects within 1 object stream 0 named destinations out of 1000 (max. 500000) 13 words of extra memory for PDF output out of 10000 (max. 10000000)

Symbol 1
  • 36,855