Why not draw circle by center and radius?

In current implementation, to draw a circle you need create three point, this seems to me very strange, and not easy to align the center of circle, for example it is very difficult to draw concentric circles, an obvious way is to draw a circle by two points, one for center, the other for any point on the circle(which define the radius), anyone know how to achieve this, or where is the start point if I want to do some hack to enable this function?

BTW, how to find the function name of specific action, for example, how to find the function for drawing this circle? Do I have to use ag or find to search the source code? Is there better way to do that?


1 Like

The code for the graphics editor is here: $TEXMACS_PATH/progs/graphics/graphics-*.scm I’m not sure which function is responsible for the circle tool but should not be difficult to find out. Also I do not see any particular obstruction to implement the drawing via center and a point on the circumference. It seems indeed odd the current approach. Do not hesitate to post here if you need some help.

Can anyone explain briefly the workflow of hacking texmacs? I suppose it should be something like:

  1. edit .scm file to add new feature
  2. compile .scm file (no idea how to compile it)
  3. restart texmacs
1 Like

.scm files are scheme programs. You do not have to compile them, they are read and run by an interpreter embedded in TeXmacs (Guile). Just restart TeXmacs. You would need some knowledge of scheme. There is a scheme shell embedded in TeXmacs (under the Sessions menu). You can modify certain definitions there and see immediately the effect.

I gave a try and it is really not difficult. Not claiming that this is the perfect solution, but one can do it as follows:

Index: TeXmacs/progs/graphics/graphics-drd.scm
--- TeXmacs/progs/graphics/graphics-drd.scm	(revision 13574)
+++ TeXmacs/progs/graphics/graphics-drd.scm	(working copy)
@@ -30,7 +30,7 @@
   line spline bezier smooth arc)
 (define-group graphical-closed-curve-tag
-  cline cspline cbezier csmooth carc)
+  cline cspline cbezier csmooth carc circle)
 (define-group graphical-curve-tag
   (graphical-open-curve-tag) (graphical-closed-curve-tag))
Index: TeXmacs/progs/graphics/graphics-menu.scm
--- TeXmacs/progs/graphics/graphics-menu.scm	(revision 13574)
+++ TeXmacs/progs/graphics/graphics-menu.scm	(working copy)
@@ -287,6 +287,7 @@
       ("Closed bezier" (graphics-set-mode '(edit cbezier))))
   ("Arc" (graphics-set-mode '(edit arc)))
   ("Circle" (graphics-set-mode '(edit carc)))
+  ("Circle2" (graphics-set-mode '(edit circle)))
   ("Text" (graphics-set-mode '(edit text-at)))
   ("Mathematics" (graphics-set-mode '(edit math-at)))
@@ -907,6 +908,7 @@
         ((== s '(edit csmooth)) "closed smooth")
         ((== s '(edit arc)) "arc")
         ((== s '(edit carc)) "circle")
+        ((== s '(edit circle)) "circle2")
         ((== s '(edit text-at)) "text")
         ((== s '(edit math-at)) "mathematics")
         ((== s '(edit document-at)) "long text")

There should be a way to add user-defined commands. Maybe one could write a small blog entry for TeXmacs blog about enhancing the graphics editor. Note that my solution do not add the corresponding menu icon.

.scm files should start with a texmacs-module declaration (see the TeXmacs Scheme developer manual, section 1.4)
Then you have to put them either inside the progs or the plugin tree of the TeXmacs user directory.

Functions defined with tm-define are visible from all TeXmacs modules and all TeXmacs documents, nevertheless you need to load a module in at least one document to be able to use them, using the macro use-module (copzing from a message I wrote time ago <use-module|([dir1 [dir2 … dirn]] filename)>).
Then you will be able to use as macros the functions you have defined by applying them through extern tags.

Apart writing functions that you use as macros, you can hack the keyboard, the menus, you can add widgets. Moreover you can manipulate the document tree using Scheme, but not via extern macros: one needs to assign the Scheme functions that manipulate the tree to keyboard actions (also menu items I think).

1 Like

thank you, I did not see new definition of circle, so this circle keyword or function in your code is build in in texmacs?

Good point: it was already defined in some of those files along with other interesting primitives like rectangle and electrical symbols. I’ve just stumbled on it while looking for how the graphics editor was working. So I’ve just reused it. A text search will give it back to you fast. It would be a nice exercise to add interface to draw rectangles, etc…

thank you for your help and explain

@mgubi it works, can you make a pr to upstream? Add a new circle or replace original one (I think we should replace old one, as it is just odd), I think this will be very convenient for users.

Yes, but I would need to complete the change and maybe discuss with Joris. Also rectangles could be a good feature. Note that if you put the modified files in your $TEXMACS_HOME_PATH/progs/graphics directory they will persist after you update TeXmacs.

1 Like

It has been solved by @Oyyko in the last year’s OSPP project.

Now, you can draw circle by center and radius. We have not ported the code to GNU TeXmacs yet. And we will port it to GNU TeXmacs in the near future.

For now, you can use Mogan Research v1.2.5.2 to enjoy this feature.