8

I am brand-new to LaTeX, Sketch, and even using the command line. My purpose is to write assignments as high-quality documents next semester for Physics, Math, Chemistry, and Engineering undergraduate-level courses. I am on break, so I figure it is a good time to learn.

I recently downloaded Sketch to use with LaTex. You will find a simplified piece of working code at the bottom.

By the way, I use Windows 8.


I am trying to create a document which includes code produced by Sketch. Below I will detail my workflow. My question is: Is there a simpler way to do this???

From what I've seen, Sketch is very powerful, and 3D images are easier to write than when using PSTricks alone. I am willing to learn Sketch. However, if there is another software or package that is just as powerful as Sketch, but much simpler to use, that would be great. (Would Inkscape be a good alternative?)


My project file hierarchy is shown below. I making use of the \input{...} command to do this. Pay special attention to the image1 folder.

  • project
    • project.tex
    • content
      • chapter1.tex (I want to include the image here.)
    • formatting
      • packages.tex, etc.
    • images
      • image1
        • sketch.exe
        • Command Prompt (Set to open in this directory.)
        • image1.sk
        • image1_standalone.tex (Contains code for the image such that it can be compiled as a standalone PDF.)
        • image1.tex (Contains the code for the image such that it can be included in the final document via \input{}.)

AFAIK, every image folder, according to my current workflow, needs all these files.


Currently, my workflow goes like this:

  1. Write Sketch code for my image in image1.sk and put global {language tikz} at the end.
    • (AFAIK, not mentioned in the documentation in any clear place. Found the tip here. Without this command, the image was not compiling at all. This might be because without this command, Sketch produces PostScript code?
    • Tangential rant: Documentation expects user knows what the Command Prompt is, how to use it, how to change directories, that the Sketch.exe needs (AFAIK) to be in the directory you are working in, etc. My computer knowledge is basic, and I wish the documentation gave this kind of information. It would have saved me a lot of time.
  2. Open the Command Prompt and type:

    Sketch -T image1.sk -o image1_standalone.tex
    pdflatex image1_standalone.tex
    
  3. Open the newly created image1_standalone.pdf file, and check whether I like how the image was produced.
    • If I don't like the image, repeat above steps.
  4. From image1_standalone.tex, copy the \usepackage{} and \usetikzlibrary{} commands into my packages.tex file.
  5. Create image1.tex and paste the code \begin{tikzpicture} ... \end{tikzpicture}...possible surrounded by \begin{center} ... \end{center}.
  6. Write \include{./images/image1/image1.tex} into the chapter1.tex file.
  7. Compile final document.

Simple example code:

    \documentclass[pdftex,12pt,letterpaper]{report}

    \usepackage[x11names,rgb]{xcolor}
    \usepackage{tikz}
    \usetikzlibrary{snakes}
    \usetikzlibrary{arrows}
    \usetikzlibrary{shapes}
    \usetikzlibrary{backgrounds}
    \usepackage{amsmath}

    \usetikzlibrary{snakes}
    \usetikzlibrary{arrows}
    \usetikzlibrary{shapes}
    \usetikzlibrary{backgrounds}


    \begin{document}
    \begin{center}
    \begin{tikzpicture}[line join=round]
    \draw(-1,-1)--(.333,.333);
    \filldraw[fill=white](0,0)--(1,0)--(0,1)--cycle;
    \draw(.333,.333)--(2,2);
    \end{tikzpicture}
    \end{center}
    \end{document}
JDG
  • 183
  • Do you need anything other than tikz for drawing? –  Dec 14 '12 at 00:58
  • @HarishKumar I do not know. I am new to Tikz, Sketch, etc. I will need to draw graphs, geometric images, chemical diagrams, etc. Do I need anything other than Tikz? Is Tikz very simple? – JDG Dec 14 '12 at 01:02
  • @HarishKumar May I ask what kind of things you use Tikz for? – JDG Dec 14 '12 at 01:04
  • @HarishKumar Thank you for the comment, but could you be more specific? What diagrams does your work require? – JDG Dec 14 '12 at 01:07
  • 1
    OK I am a physicist and teach the same. May be you get some idea. –  Dec 14 '12 at 01:08
  • 1
    I think Sketch is meant to be used only when you need to do some big graphic and you don't know how to do it quickly (then you give some code to an application and it writes lots and lots of non optimized lines of code for you, but it works). If you are starting, I would try to learn TikZ, because may be it will fit your needs, until you get to very rare situation (like a huge wall you can't jump over) and then use Sketch. – Manuel Dec 14 '12 at 01:10
  • @Manuel Ok, thank you for the recommendation. – JDG Dec 14 '12 at 01:16
  • @HarishKumar Thank you for specifying. I will try Tikz. – JDG Dec 14 '12 at 01:16
  • @Manuel Oh my god, the Tikz & PGF documentation is over 700 pages. Gah! – JDG Dec 14 '12 at 01:19
  • 1
    And, if you are plotting functions or data, pgfplots works really well. Tikz language is really easy (and so is pgfplots). About the manual.. I don't know how people learn, but I think the best way is trial and error (and a little bit of deep reeding of the documentation). You need to make a graph? Look around until you achieve it. – Manuel Dec 14 '12 at 01:20
  • @Manuel Thanks for the tips. Apparently, the documentation is extremely thorough, going from the easiest to the most obscure. Probably, I will only need less than half of the manual. Thank you. – JDG Dec 14 '12 at 01:30
  • 3
    You may also consider inkscape as a substitute for sketch. Inkscape can export to tikz. Or you can also add svg files directly into latex. –  Dec 14 '12 at 01:37
  • 1
    As an example you may look into this : Draw Bohr atomic model with electron shells in TeX? –  Dec 14 '12 at 01:41
  • @HarishKumar Thank you for the example! It's amazing! And thank you for the tip about inkscape. I will take a look at it once I feel comfortable with Tikz. – JDG Dec 14 '12 at 02:00
  • 1
    The standalone package can help you, by not having to have two almost identical tex files, it consolidades the standalone code and the code for input. – alfC Apr 21 '13 at 20:59
  • @alfC I just saw your comment. I will look into that package, thank you. – JDG Jun 10 '13 at 02:54
  • 1
    You don't have to read all 700 pages, though. Think of it as a reference. For example, there is a section explaining how to use various libraries. If you need a library, you may need to read some of the stuff on that library but you don't need to read anything about the rest until you need to use them (which may be never). – cfr May 23 '14 at 16:04
  • Elaborating cfr's comment: All you really need to read to start out using TikZ is the first tutorial (pages 28-46), which is actually somewhat entertaining as well as being informative. – Charles Staats May 23 '14 at 16:30
  • I would also note that as far as 3d images are concerned, Asymptote is a more powerful alternative to Sketch. Asymptote also has a much simpler workflow than what you describe if you use the asypictureB package with shell-escape. There are a number of Asymptote examples in the official gallery – Charles Staats May 23 '14 at 16:33

1 Answers1

1

I today started to use the combination of lualatex+tikz+sketch, the latter the newest addition. I unpacked sketch.exe to the same directory as my MikTeX binaries as the path has been setup and I will use it in general only with LaTex.

My first attempt at a workflow is by using the following:

\RequirePackage{filecontents}      
% Save the sketch as test-sk.sk 
\begin{filecontents*}{test-sk.sk}% from the sketch manual p13
def n_cyl_segs 20 def n_views 5 def I [1,0,0]
def endopts [fillcolor=lightgray]
repeat { n_views, rotate(180/n_views, [I]) then translate([I] * 2.1) }
sweep[endopts]{ n_cyl_segs<>, rotate(360/n_cyl_segs, [0,1,0]) }
line[fillcolor=white](1,-1)(1,1)

global { language tikz } 
\end{filecontents*}% the last statement was not clear, but it is required.

\immediate\write18{sketch  test-sk.sk -o sk-test.tex } %process the sketch

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\input{sk-test.tex}

\end{document}

This renders the same sketch as in manual.

Hope this is of help.

Louis
  • 1,471