chirun-ncl / chirun

A Python package providing the command line interface for building flexible and accessible content with Chirun.
https://chirun.org.uk/
Other
30 stars 4 forks source link

tikz/PDF images in Beamer slides render in HTML as images which incorrectly involve some of the whole slide #59

Closed prowlett closed 3 years ago

prowlett commented 4 years ago

There is a problem with images in Beamer slides generated from tikz and PDF graphics, which seem to render an image for the HTML version which is too large and resembled (not precisely) the whole slide. I guess because it happens with tikz and PDF but not PNG that it is an SVG issue, and I don't really understand such things.

Here is a basic example. I have put the horrible colour scheme on the background so you can see what is happening more clearly, but it happens anyway even with a default plain white background.

LaTeX code:

\documentclass[xcolor=svgnames]{beamer}
\setbeamertemplate{background canvas}[vertical shading][bottom=Blue,top=Yellow]
\usepackage{tikz}
\usepackage{makecourse}
\begin{document}
    \setbeamercolor{background canvas}{bg=yellow}
    \begin{frame}{Test}
        \begin{itemize}
            \item Here is some text.
        \end{itemize}
        \begin{tikzpicture}
        \draw[fill=blue] (0,0) rectangle (3,2);
        \end{tikzpicture}\alttext{blue box}
    \end{frame}
\end{document}

The PDF output looks like this:

pdf_output

The HTML output looks like this:

html_output

My expectation is that the HTML version will not have a background colour. As I've said, even if the slide background it is white it still makes a big slide-sized image for the HTML version.

Notice that the version of the slide that appears in the HTML image lacks the other slide content (title, text), but has the control buttons in the footer. So it is a version of the slide that only contains the picture, and the picture is not located in its proper place on the slide.

Just to confirm, this works with tikz graphics and also with images imported from PDF. Here image.pdf is a PDF made by tikz as a standalone graphic. I changed the rectangle to a circle to avoid confusion with the screenshots above.

\documentclass[xcolor=svgnames]{beamer}
\setbeamertemplate{background canvas}[vertical shading][bottom=Blue,top=Yellow]
\usepackage{graphicx}
\usepackage{makecourse}
\begin{document}
    \setbeamercolor{background canvas}{bg=yellow}
    \begin{frame}{Test}
        \begin{itemize}
            \item Here is some text.
        \end{itemize}
        \includegraphics{image.pdf}\alttext{blue circle}
    \end{frame}
\end{document}

The PDF output looks like this:

pdf_output2

The HTML output looks like this:

html_output2

However, the problem does not occur with, say, a PNG graphic. Here image.png is simply image.pdf converted to PNG.

\documentclass[xcolor=svgnames]{beamer}
\setbeamertemplate{background canvas}[vertical shading][bottom=Blue,top=Yellow]
\usepackage{graphicx}
\usepackage{makecourse}
\begin{document}
    \setbeamercolor{background canvas}{bg=yellow}
    \begin{frame}{Test}
        \begin{itemize}
            \item Here is some text.
        \end{itemize}
        \includegraphics{image.png}\alttext{blue circle}
    \end{frame}
\end{document}

The PDF output looks like this:

pdf_output3

The HTML output looks like this:

html_output3

I think it is fair to say this last image is what I expect to happen for all three. I hope that all makes sense.

prowlett commented 3 years ago

I do not mean to be pushy, and I totally understand the conflicting draws on your time, but just in case you are prioritising work on makecourse: as we are going through our graph theory section this is a problem each week for us. We have told students the PDF is a better version to look at for now and this will hopefully be fixed at some point.

georgestagg commented 3 years ago

I think to tackle this properly I will need to look carefully to really see what's going on inside plasTeX's PDF imager. Using a PNG file does not invoke the imager and that's why they seem to work better.

For the moment, does adding the following to your preamble help with your graph theory slides?

\ifplastex
\setbeamertemplate{background canvas}[default]
\setbeamercolor{background canvas}{bg=}
\beamertemplatenavigationsymbolsempty
\fi
prowlett commented 3 years ago

Yes, perfect! The HTML output now looks exactly as I expect it to.

At first I got an error (below) but realised it was because \ifplastex is defined by makecourse and I didn't have \usepackage{makecourse}.

! Undefined control sequence.
l.24 \ifplastex
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on graphs.log
georgestagg commented 3 years ago

This does seem to work really well, I've included it as part of the pdf2svg imager in 382ee3add5180057182630c5abc2bfd110179633 so that it's injected into the LaTeX preamble automatically.

I'm closing this for now, but will re-open if more problems with the same origin surface. The fix will likely be to add further lines similar to \setbeamertemplate{background canvas}[default] to reset beamer template elements back to empty or transparent.

prowlett commented 3 years ago

Brilliant! That works well for tikz images, but does not work for the case where a PDF is included using \includegraphics, which I think uses a related process. Here is an example - the first image is a tight crop with no background, but the second includes the PDF on a background with tikz controls etc. (It still works for \includegraphics using PNG images.)

\documentclass{beamer}
\usepackage{tikz}
\usepackage{graphicx}
\begin{document}

\begin{frame}
    \begin{tikzpicture}
        \draw (0,0) rectangle (1,2);
    \end{tikzpicture}
\end{frame}

\begin{frame}
    \includegraphics{image.pdf}
\end{frame}

\end{document}
georgestagg commented 3 years ago

Ah, sorry. I forgot about the non-vector imager. Hopefully 10fd295a9afecff271e8ba884e1bc1ef7d0dfc6f works with both.

prowlett commented 3 years ago

It does, thank you!