0

I have to write \Leftrightarrow quite often, and i am currently using a macro for it, but it isn't working too well. Is it possible to make it so that when i type LRA in a math field, that it then outputs it as a \Leftrightarrow? Thanks a lot for any and all help!

koleygr
  • 20,105
  • 1
    In my opinion, if this practice is generalised, it makes the code harder to read and harder to debug. This is more a problem for your editor: most editors should easily make typing \LRA a shortcut for displaying \leftrightarrow. – Bernard Oct 28 '17 at 12:15
  • 1
    welcome to tex.sx. the way your question is stated makes it seem like you want to avoid typing the backslash, as well as shortening the "name". is this really so? (if so, the answer is, well, maybe it's possible, but you really don't want to do that.) – barbara beeton Oct 28 '17 at 12:19
  • Yes i am aware that it is harder to read, but is it possible to just write LRA instead og \LRA, and if so how do you do it? – Chrisw85 Oct 28 '17 at 12:20
  • 1
    @Chrisw85 possible? Yes. Advisable? No. You could set it up in your editor (e.g. VIM's latex-suite uses similar sequences as replacement, typing SCH becomes \chapter, while typing SSE becomes \section). – Skillmon Oct 28 '17 at 12:24
  • Alright guys, thanks for the advice on keeping the backslash :) i think i will stick to it then – Chrisw85 Oct 28 '17 at 12:27
  • Depending on the editor you use you can probably make it automatically replace LRA with \leftrightarrow -- for example, this is easy with vim. –  Oct 28 '17 at 13:08
  • 2
    the alleged duplicate says nothing about defining a command without a backslash. that aspect of this question deserves its own answer as to why it's a bad idea. i'm voting to reopen. – barbara beeton Oct 29 '17 at 01:46
  • Related: https://tex.stackexchange.com/questions/107014/automatically-apply-special-formatting-to-selected-words-in-text https://tex.stackexchange.com/questions/248632/highlight-every-occurrence-of-a-list-of-words?noredirect=1&lq=1 – Torbjørn T. Oct 29 '17 at 07:34
  • You never know but sometime in the future you may write about gunnery and use LRA as a shorthand for Long Range Artillery and then be surprised when it gets typeset as a \leftrightarrow (or an error). – Peter Wilson Oct 29 '17 at 19:24
  • Off-topic: @Chrisw85 If you try to edit your question (without saving) you will see how we highlighting the in-line code – koleygr Feb 01 '18 at 03:36
  • @koleygr you can use already defined \iff which is faster to type but displays a longer version of \Leftrightarrow. – user2987828 Mar 12 '21 at 17:21
  • @user2987828 ... I think you wanted to ping the OP instead of me .... – koleygr Mar 13 '21 at 12:22
  • @Chrisw85 you can use already defined \iff which is faster to type but displays a longer version of \Leftrightarrow. – user2987828 Mar 15 '21 at 07:12
  • @koleygr oh sorry. Done. The OP has still 1 rep, so I guess he might not catch that notification at all... – user2987828 Mar 15 '21 at 07:14
  • @user2987828 ... It is his post ... If he log in again... he will be notified.... Happy TeXing – koleygr Mar 16 '21 at 13:58

3 Answers3

1

\newcommand{\LRA}{\leftrightarrow} should do the trick. You can find more detailed information here, for example.

MaxD
  • 1,137
1

Following the suggestion in How could LaTeX replace the tokens <= by the command \leq?, you can use LuaLaTeX to replace all LRAs in your code with \Leftrightarrow:

enter image description here

\documentclass{article}

\usepackage{luacode}
\begin{luacode}
function do_LRA ( buff )
  buff = string.gsub ( buff , "LRA",   "\\Leftrightarrow ")
  return buff
end
\end{luacode}
\AtBeginDocument{\directlua{luatexbase.add_to_callback ( 
    "process_input_buffer" , do_LRA, "do_LRA" )}}

\begin{document}

$ <== LRA ==> L RA << >> LR A -+ +- L R A == LRA =[ =] $

The Literacy Research Association (LRA) \ldots

The Literacy Research Association (L{}RA) \ldots

\end{document}
Werner
  • 603,163
1

Yes, it is possible. But it is questionable if it is usable.

The interesting point of your task is that you need not use \LRA but directly LRA. Then you can try the following code:

\mathchardef\mL=\mathcode`L 
\mathcode`L="8000
{\catcode`L=13 \gdef L{\futurelet\next\lraA}}
\def\lraA{\ifx\next R\expandafter\lraB \else \mL\fi}
\def\lraB#1{\futurelet\next\lraC}
\def\lraC{\ifx\next A\expandafter\lraD \else \mL R\fi}
\def\lraD#1{\Leftrightarrow}

% test:

Aha LRA in text.
In math: $LR, L, LRA$

\bye
wipet
  • 74,238