mwe.tex:
%\def\Externalize{1} %This would work perfectly
\documentclass{article}
%\documentclass[varwidth=160mm]{standalone} %This has same problem
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzset{
tex4ht inc/.style={
/pgf/images/include external/.code={%
\includegraphics[]{##1.svg}%
}
}
}
\tikzset{
external/system call/.add={}{%
; pdf2svg "\image.pdf" "\image.svg" "1"%
}
}
\makeatletter
\@ifpackageloaded{tex4ht}{
\tikzexternalize[mode=only graphics]%
}{
\ifdefined\Externalize\tikzexternalize\fi% %% This produces weird result
%\tikzexternalize %%This works as expected even when latex ... "\def\Externalize{1} \input{mwe.tex}" is used
}
\makeatother
\begin{document}
\newsavebox{\MyPictureA}%
\savebox{\MyPictureA}{%
\begin{tikzpicture} [scale=0.6, baseline={(current bounding box.center)}]
\tikzset{grid lines/.style={very thin, color=gray}}
\draw [grid lines, step=1cm] (-1.5,-1.5) grid (7.2,6.2);
\draw [very thick] (0,0) -- ++(4,0) -- ++(45:2) -- ++(0,4) -- ++(-4,0) -- ++(225:2) -- cycle;
\draw [very thick] (4,0) -- (4,4) -- (0,4);
\draw [very thick] (4,4) -- ++(45:2);
\end{tikzpicture}
}%
%
Kuutiojuuri on määritelmällisesti kolmanteen potenssiin korotuksen käänteistoimitus. Muistetaan, että kuution tilavuus saadaan laskettua korottamalla särmän pituus potenssiin kolme.
\begin{minipage}[c]{\textwidth - \wd\MyPictureA - 2em}
Esimerkiksi kuution, jonka särmän pituus on $4$, tilavuus saadaan laskemalla \mbox{$4^3=64$}.
\end{minipage}
\quad
\usebox{\MyPictureA}
Jos halutaan selvitää kuution särmän pituus, kun tilavuus tunnetaan. Pitäisi miettiä, mikä luku korotettuna potenssiin kolme tuottaa tilavuuden. Tätä laskutoimitusta voidaan merkitä kuutiojuurella.
\end{document}
Compiled with a command:
$ pdflatex --shell-escape "\def\Externalize{1} \input{mwe.tex}"
Produces a result like this:
Instead of making and external pdf of the tikzpicture it makes external pdf of the whole document.
How can I get this to compile normally?
Edit: Some additional info.
I want to achieve same thing as in here: https://tex.stackexchange.com/a/158921/103166 but only when I compile to html.
Compilation to html with externalized tikz to svg has to be done (?) in two steps:
Normal pdflatex run to produce svgs
Compilation with htlatex or make4ht to produce html that includes svgs produced during previous phase.
I also sometimes compile to regular pdf and I'd prefer not to use externalization then. Although externalization wouldn't be a problem, I would still like to know how to achieve this.
I use a bash script for compilation:
compile2html.sh:
#!/bin/bash
pdflatex --shell-escape "\def\Externalize{1} \input{$1}"
make4ht -u -e mwe.mk4 -c mwe.cfg $1
mwe.mk4:
settings.latex_par = settings.latex_par .. " -interaction=nonstopmode"
mwe.cfg:
\Preamble{xhtml,mathml,html5}
\Configure{HTML}{\HCode{<html lang="en">\Hnewline}}
{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{\HCode{\Hnewline<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?
config=MML_CHTML">
</script>\Hnewline}}
\makeatletter
\Configure{graphics*}
{svg}{
{\Configure{Needs}{File: \Gin@base.svg}\Needs{}}
\Picture[\csname a:GraphicsAlt\endcsname]{\csname
Gin@base\endcsname.svg \csname a:Gin-dim\endcsname}%
}
\makeatother
\begin{document}
\ifdefined\tikzexternalize\tikzexternalize[mode=only graphics]\fi
\ifdefined\tikzset\tikzset{tex4ht inc}\fi
\EndPreamble

\Externalizetrick, given that you use\tikzexternalizein all cases? – cfr Aug 26 '17 at 02:33\tikzexternalizein that case? Why the messing around with\Externalize? – cfr Aug 26 '17 at 14:47\@ifpackageloaded{tex4ht}{ \tikzexternalize[mode=only graphics]% }{}- why isn't this what you want? – cfr Aug 26 '17 at 14:48article.standaloneused the way you're using it will produce the whole thing as a single PDF. You should still get the picture externalised, but the situation will be a lot simpler, at least, ifstandaloneis taken out of it. – cfr Aug 27 '17 at 01:23