I am trying to extract documentation from a C++ source code file into LaTeX. Extracting the code using \lstinputlisting was simple. The problem I am having is extracting the text from comments properly.

Currently I have code like this:

    This is some text.

    This is some more text. 

I am using \lstinputlisting like so:

\lstinputlisting[linerange=//TAG_START-//TAG_END, language={}, numbers=none, frame=none, includerangemarker=false, breakindent=0pt]{file.cpp}

This kind of works, but has some issues.

  1. It outputs in preformatted font that looks nice for source code, but not regular document text.
  2. It keeps line breaks and indentations in the output, so my text ends up looking strange.

Here is what the output looks like:

Output looks like this

But I want it to look like this:

I want my output to look like this

This is me just typing text into the .tex file, this matches the rest of the document nicely.

I do not have much experience with LaTeX, so maybe there is a better way of accomplishing what I want not using \lstinputlisting, any help would be greatly appreciated.


Have you looked at catchfilebetweentags? It seems to be able to do what you are looking for, but without using \lstinputlisting.


\usepackage{catchfilebetweentags} % load the package

\newcommand{\loadFigure}[1]{ % define command to load figures
   \ExecuteMetaData[figures.tex]{#1} % call the package macro to load chunk from file

\loadFigure{fig:01} % load figure with tags id: fig:01
\loadFigure{fig:02} % load figure with tags id: fig:02


Then you can use the tags:

    ...LaTeX code...

There is a blog post here that explains the usage.


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.