1

I am using tabto package to insert tabs, I have predefined tab positions, everything works fine, but when cursor is already at tab position and I insert \tab command it skips to next tab position.

This error can be regenerated typing \tab\tab (twice consecutively).

However I want to avoid it at least for one \tab means if I type \tab\tab\tab it should only skip to two tab positions.

1
  • 3
    Could you provide a MWE?
    – bmv
    Dec 2, 2017 at 10:58

1 Answer 1

2

The following reads the next token after \tab and if it matches \tab this token is not evaluated, else it reinserts it in after \tab is executed.

\documentclass[]{article}

\usepackage{tabto}

\let\tabbak\tab

\makeatletter
\renewcommand\tab[1]{%
  \tabbak%
  \ifx#1\tab%
    \expandafter\@gobble
  \else%
    \expandafter\@firstofone
  \fi%
  #1}
\makeatother

\begin{document}
\noindent
a\tab b\tab c\tab d\\
\tab\tab\tab e
\end{document}
3
  • Thank you, that was exactly what I wanted to do. Can you suggest some good resources so that I can learn this type of advanced latex coding? Dec 5, 2017 at 19:38
  • @charlesbell just be careful on how you use it. Stuff like \tab{\bfseries foo} does break with it (meaning the \bfseries code is not grouped correctly). Commands which take arguments or don't have to be in groups work fine (e.g. \tab\textbf{foo}).
    – Skillmon
    Dec 5, 2017 at 19:42
  • On how you learn that? In my case it was writing a template package and a beamer template for my bachelors thesis and answer a whole lot of questions on TeX.SX and for those you do not know an answer read and understand how the answers provided by others work. You could as well read some stuff like the TeXbook or other exhaustive writings on TeX and LaTeX. Search TeX.SX for "good resources to learn LaTeX" or something like that. There should be enough questions about that. And if you don't understand an answer don't hesitate to ask in chat. Many times there is someone willing to explain it.
    – Skillmon
    Dec 5, 2017 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .