Is it possible to highlight text in texmacs?

Is it possible to change the background color of a word or a sentence in texmacs?

1 Like

You could try Insert -> Content tag -> Marked.

Thanks for that, but is there a way to use other colors, because it seems that only one color could be used at a time.

Yes, you can set the colour using the “Rendering options” (the eye icon in the toolbars, or go to Focus -> Rendering). The option you’re looking for is called “Marked color”.

If you want to change the colour for all marked tags in the document, you can use “Preferences” (the wrench icon or Focus -> Preferences)

I am trying to create a macro or something like that to make it easy for me to apply different highlights.

For example, the code below inserts “text” with a background color. What I want is to not to include any text with it and to be able to apply it on selected text. Can you help me write a function that does that?

  ("ho"  "" (insert '(with "marked-color" "pastel orange" (marked "text")))))

This seems to work:

(insert-go-to '(marked "") '(0 0))

You can adapt it to use a different colour as you have done in your example:

(insert-go-to '(with "marked-color" "pastel orange" (marked "")) '(2 0 0))
1 Like

This too may be helpful

1 Like

Another possibility is to use (make 'my-highlight) provided you define first a my-highlight macro which does what you want to its argument, e.g. surround it with a with and a marked tags. This should take care automatically of the selection, if any, like other TeXmacs commands e.g. “F6” for bold.

1 Like

If I may ask one more question, is it possible to define new icons on the toolbars for custom commands? There’s a massive space in the toolbar that might be put to use with custom-made icons.

This is an example that could get you on your way:

(menu-bind text-icons
  ((balloon (icon "tm_left.xpm") "Highlight")
       (insert-go-to '(marked "") '(0 0))))

This puts an extra icon on the text toolbar. The icon is just a random pick, you can change it of course.


In the code @jeroen wrote (former) refers to the former definition of the text-icons menu, which you find in $TEXMACS_PATH/progs/text/text-menu.scm. Moreover all these menus are referenced by texmacs-mode-icons which creates the mode toolbar and which is defined as

(menu-bind texmacs-mode-icons
  (if (in-source?) (link source-icons))
  (if (in-text?) (link text-icons))
  (if (in-math?) (link math-icons))
  (if (in-prog?) (link prog-icons))
  (if (in-graphics?) (link graphics-icons))
  (link help-icons))

in $TEXMACS_PATH/progs/texmacs/main-menu.scm. There are similar symbols for the other toolbars, in particular you have texmacs-extra-icons for the user customisable toolbar. It might be worth to give a look at these sources to get a feeling of how to code the toolbars.

1 Like

I like the idea of the texmacs-extra-icons toolbar, but I can’t get it to work. I have enabled the toolbar in View -> User provided icons, but I cant get an icons to appear there. I have used this example:

It seems that for text there is also a text-extra-icons menu that is intended for additional text icons. I have looked at TeXmacs/progs/education/edu-menu.scm for some inspiration.

The example by Miguel you link to works for me. I have two very small icons there using the current SVN version of TeXmacs. I haven’t tried with older versions but I guess this stuff has not been worked on lately.

1 Like

Thanks for checking! It works now. I needed to restart, apparently hiding and re-enabling the toolbar is not sufficient.

Where can I find the text toolbar?

On the second toolbar from the top, where you have icons to insert a new section, write “strong text”, etc. The icons change depending on the context of the cursor. If the cursor is in text, it will show the relevant icons on the toolbar.

I included the code snippet you posted a few posts back in init.scm file. But I don’t see any icon.


You may need to put the code in a (delayed (lazy-initialize-force) ....... ) if you put it in my-init-texmacs.scm. I only tried it from a Scheme session.

1 Like

That worked, thanks!

1 Like

Can you tell me how you came to know the number '(2 0 0) in the code above?