I have started using Asymptote for making diagrams in \LaTeX. Asymptote comes with its own Emacs mode for editing .asy files in which we typically write Asymptote code.

However, I often write a lot of asymptote code inline inside my Latex buffer.

For instance,

\documentclass{article}
\usepackage[inline]{asymptote}
\begin{document}
Save this code as \verb=test.tex= and compile it with:
\begin{verbatim}
latex test
asy test-*.asy
latex test
\end{verbatim}
\begin{figure}[h]
  \centering
  \begin{asy}
    size(350);

    real a=3;
    real b=4;
    real c=hypot(a,b);

    transform ta=shift(c,c)*rotate(-aCos(a/c))*scale(a/c)*shift(-c);
    transform tb=shift(0,c)*rotate(aCos(b/c))*scale(b/c);

    picture Pythagorean(int n) {
      picture pic;
      fill(pic,scale(c)*unitsquare,1/(n+1)*green+n/(n+1)*brown);
      if(n == 0) return pic;
      picture branch=Pythagorean(--n);
      add(pic,ta*branch);
      add(pic,tb*branch);
      return pic;
    }

    add(Pythagorean(12));
  \end{asy}
\end{figure}
The above code block should be high-lighted with fontlock of \verb=asy-mode=.
\end{document}

generate this tree from the example list on the website.

How can I enable/activate the asymptote mode syntax highlighting (or more generally the full blown asy-mode itself) when the cursor (point) is within the code-block that starts and ends with \begin{asy}....\end{asy}

More generally, how do I activate a given syntax highlighting of mode X between 2 (pre-decided) tokens when we are within working in an Emacs buffer which has major mode Y

  • I've changed your code fragment into a minimal working example. Hope that is okay for you. – Tobias Nov 7 at 3:42
  • IMHO the general way is to use mmm-mode. But your case seems to be more complicated. The package asy-mode.el tries to activate two-mode-mode which seems to be out-dated and obsolete. I've tried it without luck. I've also tried to activate mmm-mode with asy-mode. But, asy-mode bases on objc-mode which in turn bases on cc-mode and there is an open issue with the combination of mmm-mode and cc-mode. – Tobias Nov 7 at 3:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.