Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The central question is how can i convert a part of a dtx file to straight LaTeX.

In learning more about a package, I want to play with an example from a dtx? The output shows up in the pdf. The dtx, however has the code layed out like:

% \latexcommand

% some text that prints

% \morelatexcode

I cannot determine what packages are needed and why just removing the "% " does not work. The code i want to play with is from longtable.dtx, but there are other dtx files that have interesting examples that i would like to play with.

share|improve this question

2 Answers 2

I answered your question about longtable. The reason you can't just pull pieces of code out of a .dtx and expect them to work is the same reason you can't pull pieces of code out of any other TeX file and expect it to work: it can depend on the things before it.

It's impossible to give a general solution, but the trick is to just run TeX and see what error message you get which is almost certainly going to be an undefined control sequence. Then you find the piece of code in the .dtx that defines the control sequence and copy that over. Repeat until it compiles.

share|improve this answer
    
Also, somewhere at the top of the .dtx there usually is the preamble of the document (enclosed with <*driver>). –  Caramdir Apr 28 '11 at 16:51
up vote 1 down vote accepted

Here are the steps I used.

  • Copy .dtx to .tex. My ex:
cp longtable.dtx longtable_eg.tex

Edit longtable_eg_dtx.tex

  • Replace "^( *)\" with "%%% \0\" and "^( +)" with "%%% \0" This comments all dtx commands.
s/^( *)\\/\%\%\% \0\\/
s/^( +)/\%\%\% \0/
  • Insert lines at the top
\documentclass{ltxdoc} 
\usepackage{longtable} 
\begin{document} 

for lines like after the initial \if /fi pairs:

%%% \documentclass{ltxdoc} 
%%% \usepackage{longtable} 
%%% \begin{document} 
  • Insert \end{document} at end.

  • Uncomment section not in \if - \fi pair, near the top that each line starts with "% "

  • Compile (at least twice)

  • View results

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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