[Tex/LaTex] LaTeX + Sketch: Workflow—Can It Be Simpler

graphicsworkflow

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}

Best Answer

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.

Related Question