Text FormattingHow would i make the text appear in pdf as written here?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
doruido
Posts: 1
Joined: Sat Sep 10, 2016 11:50 am

How would i make the text appear in pdf as written here?

Post by doruido »

Hey completely new to LaTeX, how would i make the text in picture below appear in same order and space?
Attachments
textex.PNG
textex.PNG (11.46 KiB) Viewed 3104 times

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

How would i make the text appear in pdf as written here?

Post by Stefan Kottwitz »

Hi doruido,

welcome to the forum!

Code as image? Nice, I'll do that too. ;)

If I understand correctly, you would like to have line breaks and spaces in the output to be the same as in the source. I needed the same, some time ago, to print text configs the same as in the source.

Here's the package I wrote based on eplain.tex and used:
config.png
config.png (84.7 KiB) Viewed 3096 times
Don't worry if this looks difficult! It's easy to use. Place that code as file config.sty in the same folder as your .tex document. Her is a sample code, how it can be used:
document.png
document.png (18.28 KiB) Viewed 3096 times
The output in the PDF file is:
output.png
output.png (4.05 KiB) Viewed 3096 times
Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How would i make the text appear in pdf as written here?

Post by cgnieder »

As an alternative to Stefan's nice package :) you can also use LaTeX's own {verbatim} environment:

Code: Select all

\documentclass{article}

\begin{document}

\begin{verbatim}
algorithm exists
    lo=0
    hi=7
    while hi >= lo
        mid = floor ...
\end{verbatim}

\end{document}
There are more sophisticated packages: listings, fancyvrb and a lot more: http://www.ctan.org/topic/listing

There are also some algorithm (pseudocode) related packages: http://www.ctan.org/topic/pseudocode

Regards
site moderator & package author
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How would i make the text appear in pdf as written here?

Post by Stefan Kottwitz »

Hi Clemens,

by the way, the reason why I did not simply use verbatim, was that I needed TeX commands for loops and expansion, creating multiple config snippets in such a way:

Code: Select all

\begin{config}% white space obeyed
\foreach{\i}in{1,...,30}{%
\def\VLAN{6\twodigits{\i}}%
! Virtual interface subnet 10.16.\i.0/24 switch stack \i
interface Vlan\VLAN
  vrf member CCTV
  ip address 10.16.\i.2/24
  ip pim sparse-mode
  hsrp version 2
  hsrp \VLAN 
    authentication text HSRP\VLAN
    preempt 
    ip 10.16.\i.1
  description IPTV:10.16.\i.0/24:SWITCH\i
  no shutdown
}
\end{config}
Stefan
LaTeX.org admin
Post Reply