Dia is a cross-platform program for creating diagrams. These diagrams can be very useful for conveying information which are difficult to convey with words, but easy to visualize.

Personally, I prefer Scalable Vector Graphics (SVG) images over bitmap images, as they scale without becoming pixellated, and are therefore much more flexible. However, LaTeX isn’t capable of including those directly, and so packages like the svg package resort to hacky tricks (which require external programs and shell escaping) in order to work.

Thankfully, Dia is capable of exporting to all sorts of format, one of which is tikz, which is similar to SVG in that you programmatically define paths which scale very well.

Setup

The first step is to set up a LaTeX document. I assume you already have one, since you’re reading this article. If you don’t, the following will suffice:

\documentclass{report}
\begin{document}
\end{document}

Compiling this with LaTeX will produce an empty page.

Dia

Dia is a pretty straightforward program to use. I won’t go in depth about how it is used here, but essentially you can choose what kinds of diagrams you want to create, and then you can drag and drop standard elements onto the canvas.

The Figure

In LaTeX, a simple figure environment can be defined as follows:

\begin{figure}
    \centering % Remove this if you don't want the figure to be centered
    \input{figure.tex}
    \caption{The figure caption.}
    \label{fig:my_figure}
\end{figure}

Since Dia can export .tex files, this process allows us to include the figure as simply as by using \input{figure.tex}!

Note that you’ll need to specify the directory structure relative to the master document. I like to place my figures in graphics/.

Summary

I’ve included all of the steps and reference files below for a TL;DR.

  1. Set up the document.
  2. Create your diagram.
  3. Export the file using Export, then choose LaTeX PGF Macros (.tex).
  4. Reference the exported figure in your LaTeX document.
% Minimal document example
% e.g. master.tex
\documentclass{report}
\usepackage{tikz} % Required for .tex files generated by Dia

\begin{document}

% Referencing the figure
\begin{figure}
    \centering

    % Ensuring that the figure is scaled to 70% of the line width.
    \resizebox{0.7\linewidth}{!}{\input{graphics/figure.tex}}

    % An optional caption for the figure.
    \caption{My figure caption}

    % A label for the figure.
    \label{fig:label}
\end{figure}

\end{document}

The following figure should be placed in graphics/figure.tex, and is a simple diagram of a rectangle and a diamond with a line in between.

% graphics/figure.tex
% Graphic for TeX using PGF
% Title: /home/lihram/git/github.com/lihram/tex_document/graphics/figure.dia
% Creator: Dia v0.97.3
% CreationDate: Tue Mar 31 19:18:16 2020
% For: lihram
% \usepackage{tikz}
% The following commands are not supported in PSTricks at present
% We define them conditionally, so when they are implemented,
% this pgf file will use them.
\ifx\du\undefined
  \newlength{\du}
\fi
\setlength{\du}{15\unitlength}
\begin{tikzpicture}
\pgftransformxscale{1.000000}
\pgftransformyscale{-1.000000}
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\pgfsetstrokecolor{dialinecolor}
\definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
\pgfsetfillcolor{dialinecolor}
\definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
\pgfsetfillcolor{dialinecolor}
\fill (1.650000\du,3.550000\du)--(1.650000\du,6.850000\du)--(6.350000\du,6.850000\du)--(6.350000\du,3.550000\du)--cycle;
\pgfsetlinewidth{0.100000\du}
\pgfsetdash{{\pgflinewidth}{0.200000\du}}{0cm}
\pgfsetdash{{\pgflinewidth}{0.200000\du}}{0cm}
\pgfsetmiterjoin
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\pgfsetstrokecolor{dialinecolor}
\draw (1.650000\du,3.550000\du)--(1.650000\du,6.850000\du)--(6.350000\du,6.850000\du)--(6.350000\du,3.550000\du)--cycle;
% setfont left to latex
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\pgfsetstrokecolor{dialinecolor}
\node at (4.000000\du,5.394053\du){Box};
\definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
\pgfsetfillcolor{dialinecolor}
\fill (12.619670\du,2.608850\du)--(15.374905\du,5.047335\du)--(12.619670\du,7.485820\du)--(9.864434\du,5.047335\du)--cycle;
\pgfsetlinewidth{0.100000\du}
\pgfsetdash{{\pgflinewidth}{0.200000\du}}{0cm}
\pgfsetdash{{\pgflinewidth}{0.200000\du}}{0cm}
\pgfsetmiterjoin
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\pgfsetstrokecolor{dialinecolor}
\draw (12.619670\du,2.608850\du)--(15.374905\du,5.047335\du)--(12.619670\du,7.485820\du)--(9.864434\du,5.047335\du)--cycle;
% setfont left to latex
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\pgfsetstrokecolor{dialinecolor}
\node at (12.619670\du,5.241388\du){Diamond};
\pgfsetlinewidth{0.100000\du}
\pgfsetdash{{\pgflinewidth}{0.200000\du}}{0cm}
\pgfsetdash{{\pgflinewidth}{0.200000\du}}{0cm}
\pgfsetbuttcap
{
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\pgfsetfillcolor{dialinecolor}
% was here!!!
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\pgfsetstrokecolor{dialinecolor}
\draw (6.399555\du,5.157501\du)--(9.864995\du,5.096124\du);
}
\end{tikzpicture}