April 2, 2005 4:13 PM
As mentioned in Latex:verbatim Package, I use Latex to create reports that have a lot of code in it. I recently noticed that the verbatiminput command was silently ignoring all tabs making the code look ugly.

The solution for this was found on a mailing list. Apparently, ignoring tabs is a latex feature. To overcome this, you have to use the moreverb package and call verbatimtabinput rather than verbatiminput. If you'd rather not break existing code already written using verbatiminput, you can use the let command like so:

\usepackage{verbatim}
\usepackage{moreverb}
\let\verbatiminput=\verbatimtabinput

After doing this, latex should print tabs correctly with verbatiminput. If you want finer control over tabstops, you can re-define verbatimtabsize1 as so:

\def\verbatimtabsize{4\relax} 

I wish I had known this before I came up with:

(defun replace-tabs ()
  "Replaces all tab chars with equivalent spaces."
  (interactive)
  (let ((tabcnt 0))
    (save-excursion      
      (while 
	(re-search-forward "\t" nil t)
	(setq tabcnt (1+ tabcnt))
	;assuming tab is 8 chars
	(replace-match "        " t t nil nil)
	))
    (message "Replaced %d tabs." tabcnt)
    ))

CategoryLatex Comment(s)


[1] By default, it's eight.

Copyright © 2004-2011 Anirudh Sasikumar. All rights reserved.
Last Updated: April 2, 2005 4:43 PM