2

I am a beginner with TeX. I am trying to put a few spaces at the beginning of the line. Or a tab, whatever would work. But whatever I try it just puts space on the first line. My questions: How do I add a space in each line and is there a good cheat sheet for using TeX?

This is a text document and I am trying to add Verilog code to be shown in the final pdf version of the document. So here is an example of the latex document:


There are several ways to code a mux. Here is an example below:

\textit{\qquad input wire [7:0]} a;  \\
\textit{\qquad input wire \textit[7:0]} b;  \\
\textit{\qquad input wire [2:0] s;}   \\
\textit{\qquad output wire [7:0] fab;}  

\textit{\qquad assign fab = s[0] ? b : a;}\\  

This code infers an 8bit 2:1 mux.

enter image description here

enter image description here

  • 1
    Are you really using TeX or LaTeX? Just leave an empty line between two lines (instead of use \\) and this will produce a new paragraph with indentation. – Sigur Feb 3 '15 at 18:56
  • 2
    As Sigur says, leave a blank line to separate paragraphs. In any case, this seems like something that might require special formatting. If you tell us the whole story we might be able to find an even better solution. What are you doing? What are you trying to achieve? – Manuel Feb 3 '15 at 18:59
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Feb 3 '15 at 19:01
  • I prefer not to have spaces between the lines (though, it does solve the spacing problem). – Tlalit Feb 3 '15 at 19:28
  • I tried adding backquotes//backquotes, at the end of the line but I can see the quotes in the text. I added a gif in my original question above – Tlalit Feb 3 '15 at 19:36
3

Since you're trying to typeset code, perhaps the listings package will be helpful. You can adjust the left margin using xleftmargin.

\documentclass{article}
\usepackage[parfill]{parskip}
\usepackage{listings}
\begin{document}
There are several ways to code a mux. Here is an example below:

\begin{lstlisting}[xleftmargin=1em]
input wire [7:0] a;
input wire [7:0] b;
input wire [2:0] s;
output wire [7:0] fab;
assign fab = s[0] ? b : a;
\end{lstlisting}

This code infers an 8bit 2:1 mux.
\end{document}

enter image description here

  • 1
    To the OP, to make it —possibly— more atractive, use basicstyle=\ttfamily,columns=fullflexible in lstlisting environment options. – Manuel Feb 3 '15 at 21:29
4

there are several ways to accomplish the indentation of a block of text, where each line must remain distinct.

an easy approach is to treat each line as a paragraph by leaving a blank line after each line of the block. all the lines will be indented uniformly to the usual paragraph indentation. disadvantages: it's not easy to control breaks at the end of a page, and if the page is spaced out because of unbreakable elements, the lines of the "block" could be spaced out too.

another, not really "latex" way to handle the block is to treat it as a paragraph, breaking lines explicitly with \\, and apply a \hangindent, e.g.:

\hangindent=\parindent
\textit{\qquad input wire [7:0]} a;  \\
\textit{\qquad input wire \textit[7:0]} b;  \\
\textit{\qquad input wire [2:0] s;}   \\
\textit{\qquad output wire [7:0] fab;}  

the \hangindent persists for just the single paragraph. the \parindent shown can be replaced by any desired dimension, say .5in. disadvantage: this must be repeated for every block; although a macro could be applied to make it more compact and allow the indentation for multiple blocks to be changed uniformly with a single modification to the macro definition.

addendum: egreg suggests a quote environment. just remember that the right-hand side will be indented by the same amount as the left-hand side.

  • Why not a quote environment? – egreg Feb 3 '15 at 21:31
  • @egreg -- good question. because i didn't think of it. – barbara beeton Feb 3 '15 at 21:33
2

How about a tabular?

\documentclass{article}
\usepackage{array}
\begin{document}
There are several ways to code a mux. Here is an example below:

\begin{tabular}{>{\qquad\itshape\ttfamily\arraybackslash}l}
   input wire [7:0] a;  \\
   input wire \textit[7:0] b;  \\
   input wire [2:0] s;   \\
   output wire [7:0] fab; \\
   assign fab = s[0] ? b : a;
\end{tabular}

This code infers an 8bit 2:1 mux.
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.