Adding latex to figures from Inkscape

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}

• Why do you need psfrag if you are doing your figures in inkscape? I would either save them as pdf+latex or export them as tikzpicture from inkscape. – samcarter_is_at_topanswers.xyz Jan 11 '19 at 19:33
• Additionally to what @samcarter wrote, you can call LaTeX from within Inkscape if its only small portions of text. – Skillmon Jan 11 '19 at 19:34
• @samcarter I don't know what you mean. ARe you saying I can type $\mathcal{X}$ in my figure and then save as pdf+latex and then MikTex will build the diagram and produce the latex? (likewise with tikzpicture?) – user442920 Jan 11 '19 at 19:41
• @user442920 Yes. If you want I can write an answer to show you a short example how this is done. – samcarter_is_at_topanswers.xyz Jan 11 '19 at 19:46
• Yes, you can insert the result of a small LaTeX run. If you go into "Extensions -> Render -> LaTeX..." you can insert the document and specify packages to be loaded. – Skillmon Jan 11 '19 at 20:16

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:

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

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}
%%   \includegraphics{<filename>.pdf}
%% To scale the image, write
%%   \def\svgwidth{<desired width>}
%%   \input{<filename>.pdf_tex}
%%   \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>/}}
%%
%%   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: