GeneralAdding code to existing document.

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ubuntu2014
Posts: 29
Joined: Mon Oct 06, 2014 12:42 am

Adding code to existing document.

Post by ubuntu2014 »

Hello, I have made a diagram in xfig in ubuntu and exported it in the form of latex and it gave out the following code :

Code: Select all

\setlength{\unitlength}{4144sp}%
%
\begingroup\makeatletter\ifx\SetFigFont\undefined%
\gdef\SetFigFont#1#2#3#4#5{%
  \reset@font\fontsize{#1}{#2pt}%
  \fontfamily{#3}\fontseries{#4}\fontshape{#5}%
  \selectfont}%
\fi\endgroup%
\begin{picture}(9165,5160)(2236,-6196)
\thinlines
{\color[rgb]{0,0,0}\put(2566,-5686){\framebox(8595,4095){}}
}%
{\color[rgb]{0,0,0}\put(5221,-5686){\framebox(3555,4095){}}
}%
{\color[rgb]{0,0,0}\put(2566,-5911){\vector(-1, 0){  0}}
\put(2566,-5911){\vector( 1, 0){6255}}
}%
{\color[rgb]{0,0,0}\put(5221,-1321){\vector(-1, 0){  0}}
\put(5221,-1321){\vector( 1, 0){5940}}
}%
\put(2296,-1591){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}A}%
}}}}
\put(11386,-1501){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}B}%
}}}}
\put(2251,-5686){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}C}%
}}}}
\put(11386,-5686){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}D}%
}}}}
\put(5266,-6181){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}8 cm}%
}}}}
\put(7471,-1186){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}6 cm}%
}}}}
\end{picture}%
I just want to know that is there a way through which I can insert this code into my existing LaTeX document to give out that same image ?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Adding code to existing document.

Post by Johannes_B »

It is easier than you expect it to be, just copy the code inside.
The code as it was was resulting in a figure very big, so i made the unitlength smaller. The code is very hard to read and requires package color (or xcolor) to print black lines, which is a bit ridicoulus. Package pgf (TikZ) can be very helpful in making little schemes, flowcharts and diagrams. The documentation has a great tutorial and it is worth a look.

Code: Select all

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\setlength{\unitlength}{2444sp}%
%
\begingroup\makeatletter\ifx\SetFigFont\undefined%
\gdef\SetFigFont#1#2#3#4#5{%
  \reset@font\fontsize{#1}{#2pt}%
  \fontfamily{#3}\fontseries{#4}\fontshape{#5}%
  \selectfont}%
\fi\endgroup%
\begin{picture}(9165,5160)(2236,-6196)
\thinlines
{\color[rgb]{0,0,0}\put(2566,-5686){\framebox(8595,4095){}}
}%
{\color[rgb]{0,0,0}\put(5221,-5686){\framebox(3555,4095){}}
}%
{\color[rgb]{0,0,0}\put(2566,-5911){\vector(-1, 0){  0}}
\put(2566,-5911){\vector( 1, 0){6255}}
}%
{\color[rgb]{0,0,0}\put(5221,-1321){\vector(-1, 0){  0}}
\put(5221,-1321){\vector( 1, 0){5940}}
}%
\put(2296,-1591){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}A}%
}}}}
\put(11386,-1501){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}B}%
}}}}
\put(2251,-5686){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}C}%
}}}}
\put(11386,-5686){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}D}%
}}}}
\put(5266,-6181){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}8 cm}%
}}}}
\put(7471,-1186){\makebox(0,0)[lb]{\smash{{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}6 cm}%
}}}}
\end{picture}%
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
ubuntu2014
Posts: 29
Joined: Mon Oct 06, 2014 12:42 am

Re: Adding code to existing document.

Post by ubuntu2014 »

Thanks. Using package color or xcolor does the job. However, the link you provided to the TikZ package gave out the following message :
The re­quested URL /pkg/TikZ was not found on this server.
Also, which LaTeX software should I use ? Currently I am using Gummi. Which one do you use and which one would you recommend me using ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Adding code to existing document.

Post by Stefan Kottwitz »

The official package name for TikZ is pgf. You could use this link. You could also have a look at the TikZ example gallery.

Btw. I am using TeXworks as LaTeX editor on Ubuntu, and I'm very satisfied with it.

Stefan
LaTeX.org admin
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Adding code to existing document.

Post by Johannes_B »

I was a bit in hurry writing this, and forgot about the little discrepancy.

I would recommend using texworks as well, it is a very simple editor, nothing to distract a new user. I meself am using vim to edit my texts. The most important thing is feeling comfotable with ones editor in use.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply