[Tex/LaTex] Adding latex to figures from Inkscape

inkscapepsfrag

I have been using psfrag to add latex to figures for a while. I make my figures in Inkscape and compile in MikTex using texniccenter. I switched laptops and installed the latest Inkscape and MikTex and then psfrag stopped working. I then downgraded Inkscape to this: Inkscape 0.48.0 r9654. To no avail. Has anyone had problems like this with psfrag? What is the standard way to add latex to our figures?

Here is the code I use to swap latex into my diagrams. Am I doing anything wrong?

\documentclass[10pt]{article}

\usepackage[strings]{underscore}
\usepackage[top=1.0in,right=1in,left=1in,bottom=1.0in]{geometry}
\usepackage{enumerate}
\usepackage{wrapfig}
%\usepackage[outdir=./images]{epstopdf}

% [font=small,labelfont=bf] Required for specifying captions to tables and figures

\usepackage[dvips]{graphicx}
\usepackage[usenames]{color}
\usepackage{psfrag}
\usepackage{diagrams}
\usepackage[outdir=./]{epstopdf}
\usepackage{pstool}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
%\usepackage{caption} 
\usepackage{float}

\begin{figure}[H]
\centering
\label{HasaRelation}
\psfrag{1}{\Huge $hasA$}
\includegraphics[height= 3cm]{images/HasaConstruction.eps}
\caption{something something}
\end{figure}

Best Answer

Instead of using psfrag I would simply export the image as pdf+tex from inkscape.

For example if your image looks like this in inkscape:

enter image description here

you can save it as .pdf and select the option "omit text in pdf and create latex file" during the export:

enter image description here

This will produce two files: a pdf with just the red ellipse but without the text and a .pdf_tex file that contains the following code:

%% Creator: Inkscape inkscape 0.92.2, www.inkscape.org
%% PDF/EPS/PS + LaTeX output extension by Johan Engelen, 2010
%% Accompanies image file 'drawing.pdf' (pdf, eps, ps)
%%
%% To include the image in your LaTeX document, write
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics{<filename>.pdf}
%% To scale the image, write
%%   \def\svgwidth{<desired width>}
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics[width=<desired width>]{<filename>.pdf}
%%
%% Images with a different path to the parent latex file can
%% be accessed with the `import' package (which may need to be
%% installed) using
%%   \usepackage{import}
%% in the preamble, and then including the image with
%%   \import{<path to file>}{<filename>.pdf_tex}
%% Alternatively, one can specify
%%   \graphicspath{{<path to file>/}}
%% 
%% For more information, please see info/svg-inkscape on CTAN:
%%   http://tug.ctan.org/tex-archive/info/svg-inkscape
%%
\begingroup%
  \makeatletter%
  \providecommand\color[2][]{%
    \errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\transparent[1]{%
    \errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
    \renewcommand\transparent[1]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \ifx\svgwidth\undefined%
    \setlength{\unitlength}{595.27559055bp}%
    \ifx\svgscale\undefined%
      \relax%
    \else%
      \setlength{\unitlength}{\unitlength * \real{\svgscale}}%
    \fi%
  \else%
    \setlength{\unitlength}{\svgwidth}%
  \fi%
  \global\let\svgwidth\undefined%
  \global\let\svgscale\undefined%
  \makeatother%
  \begin{picture}(1,1.41428571)%
    \put(0,0){\includegraphics[width=\unitlength,page=1]{drawing.pdf}}%
    \put(0.30923193,0.68923333){\color[rgb]{1,1,1}\makebox(0,0)[lb]{\smash{$\mathcal{X}$}}}%
  \end{picture}%
\endgroup%

(if you need to adjust the colour or position of the text, you can simply edit this file, just make sure you are not overwriting the adjusted file in case you export again from inkscape)

This file can now easily be included in your latex document

\documentclass{article}

\usepackage{graphicx}
\usepackage{color}

\begin{document}

\begin{figure}[htbp]
\centering
\label{HasaRelation}
\def\svgwidth{.3\textwidth}
\input{drawing.pdf_tex}
\caption{something something}
\end{figure}

\end{document}

After compiling with pdflatex (or xe/lualtex) the result looks like this:

enter image description here