Document ClassesMetapost Asymptote anyone? VS pstricks

Information and discussion about specific document classes and how to create your own document classes.
skidzo
Posts: 8
Joined: Mon Sep 22, 2008 9:45 am

Metapost Asymptote anyone? VS pstricks

Post by skidzo »

Hi everyone,

I was shocked that there is only one topic that has the keyword asymptote.
I did some nice graphics that might be interesting and could also be created by pstricks or metapost, but I find the code source of asymptote more readable and clear.

I will give one very simple example just to make clear what I mean:

Code: Select all

import graph3;
import three;
import math;
texpreamble("\usepackage{bm}");

size(200,200,IgnoreAspect);

pen solid=linetype("");
pen solid=linewidth(0.4mm);

pen dotted=linetype("0 4");
pen dashed=linetype("8 8");
pen longdashed=linetype("24 8");
pen dashdotted=linetype("8 8 0 8");
pen longdashdotted=linetype("24 8 0 8");

//currentprojection=oblique;
currentprojection=perspective(3,3,3);
//currentprojection=perspective(4,2,3);
//currentprojection=perspective(4,1,2); 

label("$\rm O$", O,NW);

// Planes
pen bg=gray(0.9);
filldraw((2,0,0)--(2,0,2)--(0,0,2)--O--cycle,bg,bg);
filldraw((0,2,0)--(0,2,2)--(0,0,2)--O--cycle,bg,bg);
filldraw((2,0,0)--(2,2,0)--(0,2,0)--O--cycle,bg,bg);

draw(Label("$x$",1),O--(2,0,0),solid,Arrow);
draw(Label("$y$",1),O--(0,2,0),solid,Arrow);
draw(Label("$z$",1),O--(0,0,2),solid,Arrow);

draw(Label("$\varphi_x$",1),(1,0,-0.5)..(1,0.5,0)..(1,0,0.5),solid,ArcArrow);
draw(Label("$\varphi_y$",1),(-0.5,1,0)..(0,1,0.5)..(0.5,1,0),solid,ArcArrow);
draw(Label("$\varphi_z$",1),(0,-0.5,1)..(0.5,0,1)..(0,0.5,1),solid,ArcArrow);
can be compiled with asy.exe using TexnicCentre and the arguments -batchView -tex "pdflatex" %tc
directly to .pdf and will allways be pretty!
I had some hassle because i used Xfig and metapost .mp export and included as .mps (The only problem was to create something adequate with Xfig) I would say that there is nothing as clear and quick in doing exactly this as with the use of asymptote.

If you find something please tell me!
Attachments
graphcoordsys.pdf
(13.67 KiB) Downloaded 1436 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Metapost Asymptote anyone? VS pstricks

Post by localghost »

A very nice example. Asymptote has made into my bookmarks some time ago, but I never returned to learn more. The syntax is very similar to that of pgf/TikZ.


Best regards and welcome to the board
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Metapost Asymptote anyone? VS pstricks

Post by Stefan Kottwitz »

Hi skidzo,

welcome to the board!
That's a nice example. I just installed asymptote on Ubuntu Linux and tested your code, even before downloading the attached pdf, it worked fine.
Btw. concerning pgf/TikZ, mentioned by Thorsten, there's an example gallery by Kjell Magne Fauske.

Stefan
LaTeX.org admin
skidzo
Posts: 8
Joined: Mon Sep 22, 2008 9:45 am

Metapost Asymptote anyone? VS pstricks

Post by skidzo »

Hi Thanks,

I just afterwards heard about pgf/TikZ and the gallery is really nice!

There is also already some lang file from Kib for gedit that might be interesting, I like highlighting very much and would be pleased to have something like this in Texniccenter. Note that there is the posibility to include asymptote to your latex distribution mostly by just copying the files to the right location.
Of course you can have asymptote and metapost directly in your latex code but I don't like the idea of code merging.

You can find some information on http://www.artofproblemsolving.com/Wiki ... _Language) regarding Miktex and Texniccenter integration.

And the highlighting issue is located at http://kib2.free.fr/Gedit/AsyMode.html.

I would find it nice if someone find other editors that can do asymptote highlighting or would be easily configurable with the above lang file.

I know that scite can do beautiful Metapost highlighting.

Cheers!
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Metapost Asymptote anyone? VS pstricks

Post by CrazyHorse »

skidzo wrote: I was shocked that there is only one topic that has the keyword asymptote.
I did some nice graphics that might be interesting and could also be created by pstricks or metapost, but I find the code source of asymptote more readable and clear.
using pst_3dplot for parallel views or pst-solides3d for central views
makes life really easier ...

Herbert
curiouslearn
Posts: 105
Joined: Fri Nov 30, 2007 11:32 pm

Re: Metapost Asymptote anyone? VS pstricks

Post by curiouslearn »

I have two questions about asymptote. Would really appreciate if anyone who has an idea could comment.

(a) Does it work with pdflatex directly?
(b) Is it better at plotting functions compared to TikZ? Does it have any obvious advantages over TikZ?

Thanks very much.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Metapost Asymptote anyone? VS pstricks

Post by phi »

curiouslearn wrote:(a) Does it work with pdflatex directly?
What do you mean with "directly"? Asymptote can output PDFs, which can be easily included as graphics. Furthermore, it has an "inline" mode where it produces LaTeX instructions for labels, which has the advantage that all settings from the main document are used for the labels. Both methods work well with pdfLaTeX.
curiouslearn wrote:(b) Is it better at plotting functions compared to TikZ? Does it have any obvious advantages over TikZ?
The greatest advantage is, in my opinion, that is is not written in TeX. If you want to extend TikZ, you have to program in TeX, which is a great language for typesetting, but hardly suited for general programming or vector drawings, and its syntax is unfamiliar and involved. Asymptote has an easy yet flexible and powerful C-like syntax that can handle functions (including higher-order functions), structures, arrays, complex numbers, type checking, function overloading and so on like every decent programming language. Even simple numerical computations (root finding, solving of linear equation systems, …) are possible. I consider Asymptote a great piece of software and an ideal counterpart to LaTeX—it's sad that it receives so little attention, compared with PSTricks or TikZ. For general illustrations, mind maps, transition graphs etc., TikZ is probably better suited, because it contains comprehensive packages for that. But for graphics where a lot of calculations are needed (like function plots), Asymptote seems to be better—TikZ has to call Gnuplot for most "complicated" functions, which is very limited by itself.
curiouslearn
Posts: 105
Joined: Fri Nov 30, 2007 11:32 pm

Re: Metapost Asymptote anyone? VS pstricks

Post by curiouslearn »

Thanks very much for the information phi. You mentioned that gnuplot is limited by itself. Do you mean that asymptote is better at plotting functions compared to gnuplot?

I love TikZ and think its a great package. However, recently when preparing some slides, I found that I could not use it to plot some functions that I would have liked. I know that I can use gnuplot, but I am not familiar with it and would have to learn it.

I am asking all these questions because I am wondering whether I should spend time learning gnuplot or learning asymptote instead.

I am not sure about the correct technical term. But by "directly" I meant that can it be used with PDFLatex just like TikZ. For example, I have heard that when using "pstricks" one has to first produce DVI->PS->PDF. Does asymptote require similar steps? From your answer below it seems that this is not the case.

Thanks.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Metapost Asymptote anyone? VS pstricks

Post by phi »

curiouslearn wrote:Thanks very much for the information phi. You mentioned that gnuplot is limited by itself. Do you mean that asymptote is better at plotting functions compared to gnuplot?
Yes, definitely. Gnuplot can plot real-valued functions of one or two real variables in a specified range—nothing more, nothing less. The main objective of Gnuplot is to plot experimental data with error bars and do curve fitting. If you want contour plots or functions of complex arguments, Gnuplot is not the right tool. Sure, you can always expression complex arguments by real ones, but it is easier if the language supports built-in complex arithmetic. But for (possibly parameterized) real-valued functions of one real variable, TikZ is sufficient and there is no advantage in using Gnuplot.
curiouslearn wrote:I love TikZ and think its a great package. However, recently when preparing some slides, I found that I could not use it to plot some functions that I would have liked. I know that I can use gnuplot, but I am not familiar with it and would have to learn it.
No, TikZ is able to control Gnuplot without user interaction. It writes a Gnuplot script and executes it. The script tells Gnuplot to produce a data file with x and y values for the given function. This data file is in turn read in and plotted by TikZ. The only thing that Gnuplot really does is evaluating the function at some points—the mathematical capabilities in TeX are not strong enough for this. So you don't have to learn anything, just instruct TikZ to use Gnuplot. Have a look at the section "Plots of Functions" of the PGF/TikZ manual for an exhaustive discussion and some examples.
curiouslearn wrote:I am asking all these questions because I am wondering whether I should spend time learning gnuplot or learning asymptote instead.
If you are familiar with TikZ and have been using it to produce your figures until now, I would suggest to continue using it. It is a very sophisticated package that offers great opportunities. If you don't need the capabilities of Asymptote (like complex arithmetics, numerical computations etc.), TikZ is sufficient. Learning Gnuplot wouldn't really help in your case. Although it is quite popular among physicists (because you can draw plots for experimental data without much programming), its results are of low quality compared to those of TikZ (this is also discussed in the aforementioned section of the PGF manual; another valuable discussion is contained in the section "Guidelines on Graphics") and its capabilities of drawing error bars and doing curve fitting are not needed when you just want to draw some function graphs.
On the other hand, Asymptote is not very easy to learn, partially because the syntax is quite terse, partially because the manual is not very extensive. If you just want plots for real-valued functions of one real variable and you already know how to use TikZ, it would be overkill to learn all the bells and whistles of Asymptote.
curiouslearn wrote:I am not sure about the correct technical term. But by "directly" I meant that can it be used with PDFLatex just like TikZ. For example, I have heard that when using "pstricks" one has to first produce DVI->PS->PDF. Does asymptote require similar steps? From your answer below it seems that this is not the case.
Yes, that's right. PSTricks needs PostScript output because it relies on features of PostScript that are not offered by PDF. Asymptote is (like Gnuplot and MetaPost) an external program that takes a separate input file and compiles it to a vector graphics file (e.g., PDF or EPS), which in turn is included using \includegraphics. PSTricks and TikZ, on the other hand, use environments inside the LaTeX document without external files or programs. Both methods have their pros and cons, but for the quality of the result, this should not make a difference.

To summarize it, my suggestion is that you continue using TikZ, and let it call Gnuplot for you.
curiouslearn
Posts: 105
Joined: Fri Nov 30, 2007 11:32 pm

Re: Metapost Asymptote anyone? VS pstricks

Post by curiouslearn »

Thanks very much, Phi. That was very helpful in making my decision. I think I am going to stick to TikZ for now and use gnuplot when necessary. I definitely won't need complex arithmetic for my work. I might need the capability of solving equations to figure out the coordinates of intersections. For straight lines I know that PGF/TikZ is capable of doing that. But for more complex equations perhaps Asymptote might be more helpful.

Thanks again. The info. you provided was very helpful.
Post Reply