JavaScript and TypeScript syntax highlighting

Hello,
I’m new to TeXmacs and would like to author some software documentation with it. I really like what I have seen so far, but I’m wondering if it is possible to add syntax highlighters for code blocks in languages like JavaScript and TypeScript. With TeXmacs 2.1.1 JavaScript isn’t showing up in the list of available languages.
If those implementations are really missing, is there somewhere a documentation on how to create new highlighters?

Thanks in advance
Marc

I just found this answer in this forum:


Will try the tm-pygments plugin today…

2 Likes

Unfortunately the plugin crashes when entering code although python and pygments are installed on my system… :thinking:

Hi @dubst3pp4 and welcome to the forum.
Hopefully @jeroen, the plugin author, can help you :slight_smile:

1 Like

Hi @dubst3pp4! Welcome to the forum. The tm-pygments plugin is a work in progress.

Could you provide some more details on what happens? Which platform are you on? Do you get any error messages? Do Python sessions work on your TeXmacs?

1 Like

Hi @jeroen, thanks for the fast reply :slight_smile:

Indeed when I do Insert -> Session -> Python, I get also an error messages window with the message:

Error: Exception, segmentation fault

Unfortunately no more details are provided. How could I check them?

I’m using TeXmacs 2.1.1 on Ubuntu 21.10 64bit.

I have installed both Python versions, Python 2.7.18 which is invoked via python and Python 3.9.7 which is invoked via python3. Could this be the problem?

If you start TeXmacs from the command line, very likely you could get a stack trace which will help us to diagose the problem. How do you installed TeXmacs?

1 Like

TeXmacs looks for python3 first, then python , then python2, so I don’t expect this to be the problem. You could check by running (python-command) in a Scheme session.

1 Like

I’ve installed TeXmacs with the binaries which are provided for Ubuntu on the homepage. There is a huge stack trace written to stdout, indeed:

TeXmacs] With linked TrueType support
TeXmacs] debug-shell, Launching 'python3 -X utf8  "/usr/local/share/TeXmacs/plugins/tmpy/session/tm_python.py"'
Throwing segmentation fault
-------------------------------------------------
Error message:
segmentation fault

System information:
TeXmacs version  : 2.1.1
Built by         : magix
Building date    : Mon, 13 Dec 2021 09:55:00 +0000
Operating system : linux-gnu
Vendor           : pc
Processor        : @CONFIG_HOST_CPU@
Crash date       : Mi 16. Mär 08:24:38 CET 2022

Editor status:
Root path          : [ 0 ]
Current path       : [ 0, 0, 2, 1, 1, 0, 0 ]
Shifted path       : [ 0, 0, 2, 1, 1, 0, 0 ]
Physical selection : [ 0, 0, 0 ] -- [ 0, 0, 0 ]

Backtrace of C++ stack:
texmacs.bin : () + 0xf8cb04
texmacs.bin : () + 0x450372
/usr/lib/x86_64-linux-gnu/libc.so.6 : () + 0x42520
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : () + 0x22dc0e
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QProcess::start(QString const&, QFlags<QIODevice::OpenModeFlag>) + 0xd7
texmacs.bin : () + 0x3366cc
texmacs.bin : () + 0xe16fed
texmacs.bin : () + 0x5fe1e6
texmacs.bin : () + 0x5ff04f
texmacs.bin : () + 0x9f6cac
texmacs.bin : () + 0x116d2f7
texmacs.bin : () + 0x11692f1
texmacs.bin : () + 0x116957e
texmacs.bin : () + 0x1169cd5
texmacs.bin : () + 0x11bc551
texmacs.bin : () + 0x11bc6c5
texmacs.bin : () + 0x11bc1a1
texmacs.bin : () + 0x11bc430
texmacs.bin : () + 0xaa7a4d
texmacs.bin : () + 0xc89ebc
texmacs.bin : () + 0xc8ac86
texmacs.bin : () + 0x9f7f33
texmacs.bin : () + 0x116ce3d
texmacs.bin : () + 0x11692f1
texmacs.bin : () + 0x116957e
texmacs.bin : () + 0x1169cd5
texmacs.bin : () + 0x11bc551
texmacs.bin : () + 0x11bc6c5
texmacs.bin : () + 0x11bc1a1
texmacs.bin : () + 0x11bc430
texmacs.bin : () + 0xaa7a4d
texmacs.bin : () + 0xc89ebc
texmacs.bin : () + 0xe05cc9
texmacs.bin : () + 0xe0606a
texmacs.bin : () + 0xe069da
texmacs.bin : () + 0x328175
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : () + 0x2f0a88
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QTimer::timeout(QTimer::QPrivateSignal) + 0x3e
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QObject::event(QEvent*) + 0x1cf
/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 : QApplicationPrivate::notify_helper(QObject*, QEvent*) + 0x83
texmacs.bin : () + 0xc24871
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QCoreApplication::notifyInternal2(QObject*, QEvent*) + 0x13a
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QTimerInfoList::activateTimers() + 0x3db
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : () + 0x3121c4
/lib/x86_64-linux-gnu/libglib-2.0.so.0 : g_main_context_dispatch() + 0x26b
/lib/x86_64-linux-gnu/libglib-2.0.so.0 : () + 0xa8f08
/lib/x86_64-linux-gnu/libglib-2.0.so.0 : g_main_context_iteration() + 0x33
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 0x68
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 0x12b
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5 : QCoreApplication::exec() + 0x94
texmacs.bin : () + 0x28ff2d
texmacs.bin : () + 0x117ffd0
texmacs.bin : () + 0x11d0f2f
texmacs.bin : () + 0x11bc1a1
texmacs.bin : () + 0x11d150b
texmacs.bin : () + 0x11d15f5
texmacs.bin : () + 0x11ba6bf
texmacs.bin : () + 0x11ba707
texmacs.bin : () + 0x1180131
texmacs.bin : () + 0x269f31
/usr/lib/x86_64-linux-gnu/libc.so.6 : () + 0x29fd0
/usr/lib/x86_64-linux-gnu/libc.so.6 : __libc_start_main() + 0x7d
texmacs.bin : () + 0x28e055

-------------------------------------------------
TeXmacs] failed-error, Exception, segmentation fault

The Scheme session works without problems. When I run (python-command) in the session, I get the output "python3"

I’ve also run:

manually and got the following error:

Traceback (most recent call last):
  File "/usr/local/share/TeXmacs/plugins/tmpy/session/tm_python.py", line 19, in <module>
    tmpy_home_path = os.environ.get("TEXMACS_HOME_PATH") + "/plugins/tmpy"
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

It might be this bug:
https://savannah.gnu.org/bugs/?60931

Instead, you could try to use the generic Linux tar.gz from the website, or the AppImage:
https://download.opensuse.org/repositories/home:/slowphil:/texmacs-devel/AppImage/

I was thinking the same, somehow we have a problem with pipes in Qt 5.15, I should give a look at it…

This seems only to say that TEXMACS_HOME_PATH is not defined in the environment. You can try to set it (check a shell session in TeXmacs to see the correct value) and try manually again, but I guess that @jeroen is right.

The Shell session is also crashing… seems that only the Scheme session is able to run. I will try @jeroen suggestion (the generic tar.gz) today! Thanks for your support :+1:

2 Likes

I just had a look at the highlighting already in TeXmacs and there is in fact a JavaScript highlighter there as well. It just doesn’t seem to be very well accessible from the menus.

You can insert it either by doing \javascript-code followed by the Enter key, or you can insert a code block for another language (e.g. “Fortran code”) and then change the language to JavaScript from the toolbar.

2 Likes

Oh wow, yes, this is the result that I was looking for! And it looks even okay with added type annotations (TypeScript).

1 Like

There is still the issue of showing line numbers, for which there are two solutions none of which I have tried myself


How to add line numbering? (refers to https://savannah.nongnu.org/projects/fangle)

1 Like

For code blocks you could also use \numbered

2 Likes

Today I installed the generic package of TeXmacs and everything works now! Thanks a lot for your support! TeXmacs is a great software :+1:

2 Likes

can anyone help me to get it working
I get “Busy…” all the time