2

I use jinja to write templates. This makes me work with files like the one below.

\documentclass[a4paper, 12pt]{article}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

\newcommand\devtool[1]{\fbox{#1}}

\begin{document}

$f(x) = <:f:>$ .

\end{document}

To test my templates before using it, I would like that <:f:> works like \devtool{f}.

In other words, I would like to activate the sequences <: ... :> to be similar to \devtool{...}.

projetmbc
  • 13,315
  • 1
    This can be done with active characters or (with fewer side effects) using the process_input_buffer callback in LuaTeX, but still... wouldn’t it be easier to just use your editor to string replace <: by \devtool{ and :> by } in each document? – Gaussler Oct 14 '22 at 11:38
  • @Gaussler No I need to keep a polluted LaTeX file. This is my workflow. – projetmbc Oct 14 '22 at 18:36

1 Answers1

3

The standard procedure is to make < math active and give it a suitable definition:

  • if : follows, look up for :> and absorb everything in between, passing it to \devtool;
  • otherwise, issue a standard “less than” symbol.
\documentclass{article}
\usepackage{amsmath}

\newcommand\devtool[1]{\fbox{#1}}

\makeatletter \newcommand{\devtool@}{@ifnextchar:{\devtool@@}{\stdless}} \mathchardef\stdless=\mathcode`<

\begingroup\lccode~=< \lowercase{\endgroup\let~}\devtool@

\def\devtool@@:#1:>{\devtool{#1}}

\AtBeginDocument{\mathcode`<="8000 } \makeatother

\begin{document}

$f(x) = <:f:>$

$1<2$

\end{document}

enter image description here

egreg
  • 1,121,712