General ⇒ Arrow-producing macro using active characters
Arrow-producing macro using active characters
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 165 times
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis