# How to input text from a file between tags without source code formatting

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:

    /*
//TAG_START
This is some text.

This is some more text.
//TAG_END
*/


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:

But I want it 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.

\documentclass[11pt]{article}

\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
}
\begin{document}

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

\end{document}


Then you can use the tags:

%<*tagID>
...LaTeX code...
%</tagID>


There is a blog post here that explains the usage.

https://texblog.org/2012/12/04/keeping-things-organized-in-large-documents/