Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using Inkscape to draw images, together with the ability to produce the separate LaTeX file with all the text, as described here. So far, this has been working great, but now I am restricted to use .png, .jpeg, or .bmp for my figures.

Is there a way for me to keep using Inkscape with SVG + LaTeX and then convert to other formats from the SVG + LaTeX image (e.g. to .png) in such a way that the LaTeX fonts and their scaling are unchanged when compared to the included SVG in the document?

Additional info:

If I just draw SVG in Inkscape, add the LaTex stuff to the picture and export it to a bitmap, the LaTex text will of course not be processed.

If I use TexTex, the scaling of the fonts is lost, which is usually there for an included SVG.

share|improve this question
1  
Can you try inkscape2tikz, export everything as tikz code and \input it? –  Harish Kumar Feb 17 '13 at 13:49
    
Well, I'm restricted to using PNG, BMP, or JPEG for my images, so at the end, I need a bitmap conversion of the image and the processed LaTex symbols. –  tomislav-maric Feb 17 '13 at 13:53
1  
You may try to print the diagram in to pdf, the use imagemagick to convert it into png. –  Harish Kumar Feb 17 '13 at 13:55
    
@HarishKumar Thanks, I'll try this. As another option, I just opened the pdf_tex file, and noticed the "put" command with the latex text. Would it be possible also to export the SVG without the text into a PNG and re-use the put commands to place the symbols on the image? –  tomislav-maric Feb 17 '13 at 14:06
    
Another, different approach could be GIMP. It can read SVG files and can save them in (e.g.) PNG format. (I do not know ImageMagick well enough, but perhaps this is also possible with convert.) –  Speravir Feb 17 '13 at 18:41
show 4 more comments

1 Answer

Install inkscape2tikz. The following example is taken from inkscape2tikz home page.

enter image description here

Using inkscape2tikz we export this in to tikz code:

\documentclass{article}
\usepackage{tikz}
\usepackage{charter}               %%%% Added for demo of fonts

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\definecolor{cff8080}{RGB}{255,128,128}

\begin{tikzpicture}[y=0.80pt,x=0.80pt,yscale=-1]
\begin{scope}[draw=black,line join=round,miter limit=4.00,line width=3.200pt]
  \path[draw=black,fill=cff8080,line join=round,even odd rule,line cap=butt,miter
    limit=4.00,line width=3.200pt] (91.0455,165.7194) rectangle
    (250.7252,347.8104);
  \path[draw=black,line join=round,even odd rule,line cap=butt,miter
    limit=4.00,line width=3.200pt] (168.0839,258.1656) .. controls
    (169.6992,260.2725) and (166.0408,261.3824) .. (164.5822,260.8503) .. controls
    (160.6293,259.4083) and (160.6636,254.1057) .. (162.7146,251.1621) .. controls
    (166.3833,245.8967) and (174.0594,246.2369) .. (178.5892,250.1116) .. controls
    (185.2369,255.7979) and (184.5602,266.1224) .. (178.8226,272.1726) .. controls
    (171.1753,280.2366) and (158.1221,279.2067) .. (150.5752,271.5890) .. controls
    (141.0782,262.0028) and (142.4690,246.1872) .. (151.9759,237.1551) .. controls
    (163.4900,226.2161) and (182.0854,227.9716) .. (192.5962,239.3729) .. controls
    (204.9828,252.8090) and (202.8604,274.1941) .. (189.5613,286.1796) .. controls
    (174.2071,300.0173) and (150.0257,297.5267) .. (136.5682,282.3277) .. controls
    (121.2770,265.0577) and (124.1368,238.0757) .. (141.2372,223.1481) .. controls
    (160.4213,206.4017) and (190.2069,209.6312) .. (206.6032,228.6342) .. controls
    (224.8061,249.7311) and (221.2064,282.3227) .. (200.3000,300.1866);
\end{scope}

\end{tikzpicture}
\end{document}

Call this file as image.tex (say). Following is your main.tex file. Put image.tex and main.tex in the same folder. For this example, I have added image.tex by filecontents.

\documentclass{article}
\usepackage{graphicx}
\usepackage{charter}                  %%%% Added for demo of fonts Keep this in image.tex also to have same fonts
\usepackage{filecontents}
\begin{filecontents*}{image.tex}      
    \documentclass{article}            %%% tex file for image begins
    \usepackage{tikz}
    \usepackage{charter}               %%%% Added for demo of fonts
    \usepackage[active,tightpage]{preview}
    \PreviewEnvironment{tikzpicture}

    \begin{document}
    \definecolor{cff8080}{RGB}{255,128,128}

    \begin{tikzpicture}[y=0.80pt,x=0.80pt,yscale=-1]
    \begin{scope}[draw=black,line join=round,miter limit=4.00,line width=3.200pt]
      \path[draw=black,fill=cff8080,line join=round,even odd rule,line cap=butt,miter
        limit=4.00,line width=3.200pt] (91.0455,165.7194) rectangle
        (250.7252,347.8104);
      \path[draw=black,line join=round,even odd rule,line cap=butt,miter
        limit=4.00,line width=3.200pt] (168.0839,258.1656) .. controls
        (169.6992,260.2725) and (166.0408,261.3824) .. (164.5822,260.8503) .. controls
        (160.6293,259.4083) and (160.6636,254.1057) .. (162.7146,251.1621) .. controls
        (166.3833,245.8967) and (174.0594,246.2369) .. (178.5892,250.1116) .. controls
        (185.2369,255.7979) and (184.5602,266.1224) .. (178.8226,272.1726) .. controls
        (171.1753,280.2366) and (158.1221,279.2067) .. (150.5752,271.5890) .. controls
        (141.0782,262.0028) and (142.4690,246.1872) .. (151.9759,237.1551) .. controls
        (163.4900,226.2161) and (182.0854,227.9716) .. (192.5962,239.3729) .. controls
        (204.9828,252.8090) and (202.8604,274.1941) .. (189.5613,286.1796) .. controls
        (174.2071,300.0173) and (150.0257,297.5267) .. (136.5682,282.3277) .. controls
        (121.2770,265.0577) and (124.1368,238.0757) .. (141.2372,223.1481) .. controls
        (160.4213,206.4017) and (190.2069,209.6312) .. (206.6032,228.6342) .. controls
        (224.8061,249.7311) and (221.2064,282.3227) .. (200.3000,300.1866);
    \end{scope}

    \end{tikzpicture}
    \end{document}
\end{filecontents*}                   %%% tex file for image ends
% compile with pdflatex
\immediate\write18{pdflatex image}
% convert to PNG
\makeatletter
\immediate\write18{convert -density 500 -alpha on image.pdf image.png}
\makeatother
%
\begin{document}
\includegraphics[width=5cm]{image}    %%% insert .png file
\end{document}

This assumes that you have imagemagick installed.

share|improve this answer
    
It's very helpful indeed: with svg2tikz Asymptote pictures can be converted to tikz, since one of the supported output formats in Asymptote is svg. –  g.kov Apr 10 '13 at 20:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.