koppor/plantuml

Can't use SVG with multiple diagramms

smennig opened this issue ยท 6 comments

If I use svg as output I can not include more then one diagram.
Example:

\documentclass{scrartcl}

\usepackage{graphics}

% Enables inclusion of SVG graphics - 1:1 approach
% This is NOT the approach of https://ctan.org/pkg/svg-inkscape
% which allows text in SVG to be typeset using LaTeX.
% We just include the SVG as is.
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule{.svg}{pdf}{.pdf}{%
  inkscape -z --file=#1 --export-pdf=\OutputFile
}

\usepackage[output=svg]{plantuml}

\begin{document}
\begin{plantuml}
	@startuml
	class Car
	
	Driver - Car : drives >
	Car *- Wheel : have 4 >
	Car -- Person : < owns
	@enduml
\end{plantuml}

\begin{plantuml}
	@startuml
	class B
	
	A - B : drives >
	B *- D : have 4 >
	B -- C : < owns
	@enduml
\end{plantuml}

\end{document}

Ok renaming the PlantUMLJobname like \def\PlantUMLJobname{second} has worked for me.

\documentclass{scrartcl}

\usepackage{graphics}

% Enables inclusion of SVG graphics - 1:1 approach
% This is NOT the approach of https://ctan.org/pkg/svg-inkscape
% which allows text in SVG to be typeset using LaTeX.
% We just include the SVG as is.
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule{.svg}{pdf}{.pdf}{%
	inkscape -z --file=#1 --export-pdf=\OutputFile
}

\usepackage[output=svg]{plantuml}

\begin{document}
	\begin{plantuml}
		@startuml
		class Car
		
		Driver - Car : drives >
		Car *- Wheel : have 4 >
		Car -- Person : < owns
		@enduml
	\end{plantuml}
	
	\def\PlantUMLJobname{second}
	\begin{plantuml}
		@startuml
		class B
		
		A - B : drives >
		B *- D : have 4 >
		B -- C : < owns
		@enduml
	\end{plantuml}
	
\end{document}

Ist there a mecanism to automate this?

Related: #17

@smennig thank you for your solution.
As a mechanism I would suggest:

\newcounter{PlantUML}
\def\UMLcountUp{\stepcounter{PlantUML} \def\PlantUMLJobname{PlantUML\thePlantUML}}

and call it after each \end{plantuml} or before every \begin{plantuml}

\documentclass{scrartcl}

\usepackage{graphics}

% Enables inclusion of SVG graphics - 1:1 approach
% This is NOT the approach of https://ctan.org/pkg/svg-inkscape
% which allows text in SVG to be typeset using LaTeX.
% We just include the SVG as is.
\usepackage{epstopdf}
% --export-type="pdf"
\epstopdfDeclareGraphicsRule{.svg}{pdf}{.pdf}{%
%example-component-diagram-plantuml-svg-converted-to
  inkscape #1 --export-text-to-path --export-filename=\OutputFile
}
\usepackage[output=svg]{plantuml}

\newcounter{PlantUML}
\def\UMLcountUp{\stepcounter{PlantUML} \def\PlantUMLJobname{PlantUML\thePlantUML}}

\begin{document}

	\begin{plantuml}
		@startuml
		() "Interface 2" as I2
		() "Interface 3" as I3

		[component 1] as c1
		[component 2] as c2
		[component 3] as c3
		
		c1 -- I2
		c1 -- I3
		
		I2 )-- c2
		I3 )-- c3
		@enduml
	\end{plantuml}
	\UMLcountUp

	\begin{plantuml}
		@startuml
		class Car
		
		Driver - Car : drives >
		Car *- Wheel : have 4 >
		Car -- Person : < owns
		@enduml
	\end{plantuml}
	\UMLcountUp
\end{document}

But it would be nice if something like:

\newcommand{\myplantuml}[1]{%
	\UMLcountUp
	\begin{plantuml}
		@startuml
		#1
		@enduml
	\end{plantuml}
}

could work...

in the plantuml.sty you can change some parts...
I'm not sure if you should, so all on your own risk.

Line 27 you can change to:

% \jobname has an encoding issue if the .tex filename includes a multibyte string.
% One needs to redefine PlantUMLJobname to fix it
\newcounter{PlantUmlFigureNumberSVG}
\def\UMLcountUp{\stepcounter{PlantUmlFigureNumberSVG} \def\PlantUMLJobname{PlantUML\thePlantUmlFigureNumberSVG}}
\def\PlantUMLJobname{\jobname\thePlantUmlFigureNumberSVG}

original line 96 (if you added the code above it will be line 98)

{
      \includegraphics[width=\maxwidth{\textwidth}]{\PlantUMLJobname-plantuml.\PlantUmlMode}
      \UMLcountUp
    }

Worked for me - you will have a mess in the build folder => be sure to clean up a little bit...

koppor commented

@NWest09 Looks good. Can you submit a pull request so that I can work on having the fix published on CTAN?

I will work on Friday or Saturday to submit the code. (I'm not sure if I set up everything correct but I think so)