0

I have a document in LaTeX in which I have to use a lot of code over and over again. Is it possible to define this code somewhere with a shortcut so that I can call it up by only using the shortcut in the real code? I also want to be able to use it in all environments.

An example to make my question more understandable:

  • repeated code: acbdbad
  • shortcut: \a
  • Real code: dakjmdka \a dkqjdk \a dqksjf \a

Is there also a name for this? This is probably something quite straightforward but I'm new to Latex and I have no idea what it is called, so it's hard to find on the web.

Thank you in advance!

Torbjørn T.
  • 206,688
Barrie
  • 43
  • Can you give a more realistic example? In some cases, it will depend on what you're trying to repeat. If it's just text: \newcommand\a{acbdbad} – Sean Allred Dec 29 '13 at 19:35
  • 1
    You basically want \newcommand\myshortcut{abcdbad}, but as Sean says it may depend on the use case. Edit: How does algorithms come into this, by the way? – Torbjørn T. Dec 29 '13 at 19:37
  • 1
    @SeanAllred There is a bunch of single letter macros defined by default, including \a, so some care should be taken. See http://tex.stackexchange.com/questions/19111/short-names-for-macros – Torbjørn T. Dec 29 '13 at 19:41
  • @TorbjørnT. I know that, but I was trying to keep the correlation in the example OP provided; yours luckily maintains clarity while setting a good example, but I guess it's good to mention this to OP. – Sean Allred Dec 29 '13 at 19:42
  • 1
    @SeanAllred Ah, ok. I thought I should mention it as your example will generate an error. – Torbjørn T. Dec 29 '13 at 19:47

0 Answers0