Text FormattingPreserve space and line break formatting on cut and paste

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Preserve space and line break formatting on cut and paste

Post by ptrcao »

I wanna paste the following directly from my Linux terminal into my latex editor. But I want the formatting, in particular, the line breaks and the spacing to be preserved. How, please?

Code: Select all

peter@peter-ubuntu:/media/SAMSUNG$ sudo fdisk -l
[sudo] password for peter: 

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd21cd21c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       66046   530508440+   7  HPFS/NTFS
/dev/sda2           66046      121602   446253057    5  Extended
/dev/sda5           66046       94882   231630865   83  Linux
/dev/sda6          120781      121602     6589440   82  Linux swap / Solaris
/dev/sda7   *       94883      119960   201434112   83  Linux
/dev/sda8          119960      120780     6589440   82  Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb19cf899

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       60801   488384000+   7  HPFS/NTFS
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Preserve space and line break formatting on cut and paste

Post by Stefan Kottwitz »

You could use a verbatim environment:

Code: Select all

\begin{verbatim}
... % paste your text here
\end{document}
There are packages such as fancyvrb and examplep providing further verbatim environments. You could also use the listings package which provides further formatting features.

Stefan
LaTeX.org admin
Post Reply