10

I have a line like this:

line.tex:

\documentclass[12pt]{article}
\usepackage{asymptote}
\begin{document}

\begin{asy}
unitsize(1cm);
defaultpen(0.5cm);

draw((0,0)--(1,1));
\end{asy}

\end{document}

latexmrc:

sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");

As expected, it draws a solid line with rounded edges like this:

However, I would like to draw just the outer border of that line, something like this:

How can I do this?

AMACB
  • 203
  • 1
  • 6
  • Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Jun 05 '16 at 01:14
  • Sorry I don't know much about Asymptote, but what you provided produces no output for me. Is there something special I need to run when using Asymptote, besides pdflatex? – Peter Grill Jun 05 '16 at 01:18
  • I also have the latexmrc file with some code in it, will edit in a sec. – AMACB Jun 05 '16 at 01:23
  • A user here, Malipivo, has used a \pdfliteral feature to do outlines of glyphs, which may apply in your situation. Here are some examples: http://tex.stackexchange.com/questions/169636/proper-outline-in-devanagari-and-arabic-fonts, and http://tex.stackexchange.com/questions/18472/tikz-halo-around-text/169549#169549. – Steven B. Segletes Jun 05 '16 at 01:38
  • @StevenB.Segletes Can't seem to make that work with a line in asymptote. – AMACB Jun 05 '16 at 01:44
  • I don't have asymptote on my system, but I reduced Malipovo's code down to the essentials, if that helps in an adaptation: \documentclass{article} \input pdf-trans \newbox\qbox \begin{document} \def\maltext{\Huge$-$} \setbox\qbox=\hbox{\maltext}% \boxgs{Q q 2 Tr 0.4 w 0 0 0 RG 1 1 1 rg }{}% \copy\qbox \end{document} – Steven B. Segletes Jun 05 '16 at 01:57

3 Answers3

5

You can over-draw it using a pen with the background colour and a slightly narrower width.

Here's an example: (compile with asy or integrate into your existing LaTeX doc).

unitsize(1cm);
guide sausage = (0,0) -- (2,3);
draw(sausage, black+5);
draw(sausage, white+4.2);

this produces:

enter image description here

The draw(*guide*, *pen*) command draws the guide with the specified pen. To set the width of your pen, you just add a real number to an existing pen. In this case I've used the predefined (coloured) pens black and white. Adding 5 to black makes a pen that's 5 PostScript points wide. If you wanted one that's 5mm wide then you could do black+5mm thanks to the clever way that Asymptote deals with units.

Thruston
  • 42,268
  • That almost works, but the problem is I need to make these overlap each other, which doesn't work with this approach. – AMACB Jun 06 '16 at 01:47
  • OK, perhaps you can update the question to say that? – Thruston Jun 06 '16 at 06:59
  • Getting the outline of a stroked path is hard -- I don't think it's implemented in Asymptote (but I'm not an expert). You would certainly find it easier to define oval paths and draw them directly. Could you try that approach? – Thruston Jun 06 '16 at 08:28
4

I have taken the idea in this post, using the graph package to construct the path[] getBorder(path, pen) function as shown in the following code.

unitsize(1inch);
import graph;

path[] getBorder(path p, pen origPen)
{
    real offset = linewidth(origPen)/2.0/72.0;
    pair offsetPoint(real t) { return point(p, t) + offset*(rotate(90)*dir(p,t)); }
    path path1 = graph(offsetPoint, 0, length(p), operator ..);
    offset = -offset;
    path path2 = graph(offsetPoint, 0, length(p), operator ..);

    path[] paths;
    if (cyclic(p)) { paths = path1^^path2; }
    else { paths = path1..reverse(path2)..cycle; }

    return paths;
}

pen origPen = 10+black;

draw(getBorder((0,0){E}..{S}(2,0), origPen), red);
draw(getBorder((0,1)--(1,0), origPen), blue);
draw(getBorder(shift(1,0.5)*scale(0.5)*unitcircle, origPen), green);

enter image description here

The code works for cyclic or non-cyclic paths. The origPen definition determines the resulting width of the path outline. The function assumes that the origPen is defined with a roundcap.

Unfortunately, the nature of the function means that sharp corners or small radii will not be treated properly. Maybe someone else knows how to overcome this problem.

enter image description here

James
  • 4,587
  • 1
  • 12
  • 27
0

I think you should change the size of defaultpen to something less that what you are using, i.e., less than 0.5cm.

I hope this helps!

Werner
  • 603,163
  • I'm trying to draw the region within a certain length of the line, not what you are doing. – AMACB Jun 05 '16 at 12:24