Question : How can I insert a txt file ( a source code) as such in latex without any change in indentation, tabs, formatting etc?
Scenario :
Consider I have a text file as below ( It is a part of a VHDL code edited in gEdit ):
I want to include this code in Latex as it is.
I used verbatim method available in Kile, and below is the result I got :
You can see the tabs and indentation is dislocated. ( This is just a small part, remaining part is also similar, means, everything dislocated)
How can I add this code as such into a latex file ?
EDIT :
I also used listings
package. Again the same problem. Intendation is not correct. Also, it even cut some portions of text on the right side.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TOP_MODULE is
port (CLK : IN STD_LOGIC; -- clock
RESET : IN STD_LOGIC; -- reset signal
DECODED_DATA : OUT STD_LOGIC_VECTOR(0 TO 15) -- decoded message
);
end TOP_MODULE;
Best Answer
You probably have tabs in your input file. You can, however, fix it without changing your input file, with either
fancyvrb
orlistings
; both packages allow also for making the type size smaller, so that the code fits in the margin.In the example, the line that shows only
);
has a tabulation character in it, just to show that the packages can cope with it. It's, to be precise,so that in my editor, where tabs cover 8 spaces, it is right for aligning the parentheses under the "D" in the line above it.
However, changing tabs into spaces is better: editors have different ideas about how long is a
<TAB>
, so what aligns in an editor may appear misaligned in another.