GeneralArrow-producing macro using active characters

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
linusk
Posts: 1
Joined: Sun Apr 24, 2011 9:31 pm

Arrow-producing macro using active characters

Post by linusk »

Hello!

I'm trying to create a macro that lets me input right-pointing arrows with a more intuitive syntax than the usual $\rightarrow$ or $\longrightarrow$. I'm doing this mostly for fun and to understand TeX/LaTeX better.

What I want to accomplish is the following:

-> should expand to $\rightarrow$
--> should expand to $\longrightarrow$

My solution is based on changing the category code of the hyphen character so it becomes active, and then \def-ining it to start a "parse" of the succeeding tokens in the file. My solution so far is attached to this post.

The problem I have is that when a string of tokens that should not produce an arrow, for example --<, is processed by my macros, I want the result to be the same as if there were no macros defined at all. In this example I want the first two hyphens to produce the usual "en dash", but with my macros, the result is two separated hyphens. I guess this has something to do with TeX loosing track of that the two hyphens "belong" to each other while expanding the macros.

Any ideas on why this happens? Thanks a lot in advance!
/Linus
Attachments
arrow.tex
(1.69 KiB) Downloaded 162 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply