# Make a command to mark a text and class them for text analyze

Sorry for my English, I'm French and it's my first post on this forum, but I'm a frequent visitor of this forum, thanks for all ;)

My problem is this : I'm working with transcriptions of 35 interviews (1000 pages) and I'm trying to build a command (environment or package?) to mark my linear text with some (sub)commands (margin braces, highlighting) in a first part, and after, copy and redirect this marked text to a thematic classification in a second part.

My idea : I'd like to use my command in the text like this:

\marque{#1}{#2}{#3}{#4}{#5}


or

\begin{\marque}{#1}{#2}{#3}{#4}#5\end{\marque}


I need 3 functions for this command:

• to mark paragraphs (#5) of the first part with 5 specific layouts, according to #1 value
• text (#5) and titles (#2 #3 #4) extraction for driving to a tree structure (maybe in 5 files: his.tex phi.tex com.tex sem.tex est.tex)
• integrate this new structure with titles and text to the 2nd part (without layouts from part 1)

Details of the command:

{#1}= title 1 (which doesn't appear in part 1) associated with a layout

• if#1=[his]
• layout=\encadre
• drive to his.tex
• if#1=[phi]
• layout=\accoladedroite
• drive to phi.tex
• if#1=[com]
• layout=\parentgauche
• drive to com.tex
• if#1=[sem]
• layout=\surlignage
• drive to sem.tex
• if#1=[est]
• layout=\crochetdroit
• drive to est.tex file

{#2}= title 2 which appears in both parts

• appear in the layout (so included in the layout command: \marque{#2}=\crochetdroit{#1})
• drive on the associated file (#1) in a made section, otherwise create a new section named #2 (the new text of #2)
• if #2 doesn't correspond with any section in #1 file, write at end \section{titre 2} (for example in file his.tex)
• if #2 corresponds with a section in #1 file, (ex: his.tex), do nothing

{#3}= title 3 which appears in both parts

• appear in the layout
• drive
• if #3 doesn't correspond with any subsection in #1 file and \section{#2}, write at end of this section \subsection{title 3}
• if #3 corresponds with subsection in #2 section in #1 file, do nothing

{#4}= title 4 which appears in both parts

• appear in the layout
• drive (like #3) to make a \subsubsection{title 4}

{#5}= text which appears in both parts

• appear in the layout
• drive
• appear under \subsubsection{#4} of \subsection{#3} of \section{#2} of #1 file (ex: his.tex)

To include texts from files to part 2, after part 1 \part{Les interviews}, write part 2:

\part{L'analyse}
\chapter{Histoire}
\include{his.tex} %(or \input ?)
\chapter{Philosophie}
\include{phi.tex}
\chapter{Communication}
\include{com.tex}
\chapter{Sémantique}
\include{sem.tex}
\chapter{Esthétique}
\include{est.tex}


See example illustrated in document attached:

\part{Les interviews}
\chapter{Interview 1}
\marque{his}{Inspiration}{Expiration}{}{text 1
\marque{com}{thèse}{Action 136}{}{text 2
\marque{phi}{Steak}{Pastèque}{Aztèque}{text 3
\marque{est}{Uchronie}{Carotte}{}{text 4}
\marque{est}{Anachronie}{C}{V}{text 5}
\marque{est}{Reconstitution}{Carotte}{Carotte}{text 6}
\marque{est}{Achronie}{L'actrice}{La Lapistou 1567}{text 7}}}
text 8
\marque{est}{5678 The}{action}{veste}{text 9}
text 10}


And, in the second part:

Histoire
Inspiration
Expiration
texte 1-2-3-4-5-6-7-8-9-10
Philosophie
Steak
Pastèque
Aztèque
texte 3-4-5-6-7
Communication
Thèse
Action 136
texte 2-3-4-5-6-7
Sémantique
Esthétique
Uchronie
Carotte
texte 4
Anachronie
C
V
texte 5
Reconstitution
Carotte
Carotte
texte 6
Achronie
L'actrice
Le lapistou 1567
texte 7
5678 The
action
vest
texte 9


So! I know how to make layout (sub)command, for example, the \parentgauche command, or \temporal

\newcommand\parentgauche[4]
{\par
\smallskip
\makebox
[\textwidth][r]
{$\rotatebox[origin=c]{90}{#1} \rotatebox[origin=c]{90}{\color{gray}#2-\textit{#3}} \left( \begin{minipage}{\textwidth}#4\end{minipage} \right. \nulldelimiterspace=0pt$}
\par
\smallskip}}

\newcommand{\choixcouleur}[1]
{\ifthenelse{\equal{#1}{uchronie}}{\sethlcolor{Apricot}}{}%
\ifthenelse{\equal{#1}{achronie}}{\sethlcolor{Tan}}{}%
\ifthenelse{\equal{#1}{anachronie}}{\sethlcolor{Salmon}}{}%
\ifthenelse{\equal{#1}{reconstitution}}{\sethlcolor{Peach}}{}}
\newcommand{\temporal}[4]
{\choixcouleur{#1}\hl{#4}\footnote{{\textbf{#1}#2\textit{#3}}}}


But, I don't know how to built commands to: - copy/paste (I know cut/paste, but I need the text in part 1) - extract, - write in another file, - drive in this file.

Maybe it's better to create files not only for chapter, but also for section subsection & subsubsection too?

That's my config:

\documentclass{scrbook}
\usepackage{fontspec}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage[applemac]{inputenc}
\usepackage{lmodern, textcomp}
\usepackage[T1]{fontenc}
\usepackage[frenchb]{babel}
\frenchbsetup{FrenchFootnotes=false}
\usepackage{eco}
\usepackage[babel,french=guillemets*]{csquotes}
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{soul}
\usepackage{multicol}

• By the way, I wanted to add an image to better explain, but, no possible yet for me, as I'm too new. Aug 13, 2013 at 14:34
• Add the images and remove the initial ! then we can add them for you until you get some rep points. Aug 13, 2013 at 14:40
• Your question is very comprehensive, requiring a great deal of work, It was worthwhile to hope that your question would resonate with a developer already thinking about a similar problem. That has not yet happened. If your bounty is unsuccessful, you may consider distilling the question to its essence, and subdividing the challenges into simpler sub-tasks, each asked as its own question. You are more likely to get help, if someone can answer the sub-question in 30 minutes, rather than having to make an independent research project of it. Mar 14, 2014 at 15:34
• Ok, thank you for your experienced advice @Steven_B._Segletes, I wait for the bounty. If no one has any idea, I'll divide my question. Mar 14, 2014 at 16:05
• @sheß Thank you for your answer, I think I'm looking for something like that, yes. I have to try with my code, & I tell you if it works… Mar 20, 2014 at 9:32

General tips (longer post)


If it is only matter of internal blocks of code, we can introduce an extra parameter in the definition (the second half of the example). After that changing a style is only a matter of changing one word/character. Those commands could be even redefined automatically as a portion of the \part command as its counter is changed internally.

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{xcolor}
\begin{document}
\def\mystyleA#1{{\color{blue}#1}}
Part 1: First line \mystyleA{in a style.}\par
\def\mystyleA#1{{\color{red}#1}}
Part 2: First line \mystyleA{in a style.}\par\medskip
\def\mystyle#1#2{{\color{#2}#1}}
Part 1: First line \mystyle{in a style.}{magenta}\par
\def\mystyleA#1{{\color{red}#1}}
Part 2: First line \mystyle{in a style.}{cyan}\par
\end{document}


Framing: Sooner or later you will run into a problem of framing more pages. Packages like mdframed, Conserve the frame in a mdframed box that spans more than one page, and tikzmark, Tikz - How to overlay Decorations over longtable, are a good start.

Levels: To have an idea on which level of command you are, you can use a counter. We can use groups for this purpose (entering and leaving group), but in the following example I used a simple +1 and -1 approach which is easy to read. You can control flow, such as styles, by \ifnum and \ifcase.

\documentclass[a4paper]{article}
\pagestyle{empty}
\begin{document}
\newcount\level \level=0 % Initializing a counter.
\global\def\mylevel#1{%
\advance\level by 1 % Increase a counter.
I am on level \the\level. % Show the value.
\ifnum\level=1 Level 1. \fi  % Simple condition.
\ifcase\level Nill.\or One.\or Two.\else Other level.\fi\ % More complex condition.
% Regular part of the command.
#1
I am back on level \the\level.} % End of the command.
% Test of just one level...
Text. \mylevel{Test1.} More text. \mylevel{Test2.} The end.\par
% Test of more levels...
\level=0 % Manual setting of the counter.
Text. \mylevel{This is my code \mylevel{fractioned \mylevel{into \mylevel{many \mylevel{parts.}}}}}
\end{document}


Note. Next to the common structure (\section, \subsection etc.) we could use numbers indicating a level. It depends on a task. Such a plain data+text file is usually easier to parse, store and re-use.

1 My part
2 My chapter
2 My second chapter
3 My first section
3 My second section


Storing and re-using blocks internally: We can store blocks by expanding a command. Please take a look at the etoolbox package or at https://tex.stackexchange.com/questions/97901/how-can-i-store-variables-in-lists-and-make-use-of-them. I enclose a basic example.

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{etoolbox}
\usepackage{xcolor}
\begin{document}
\def\mysentence{I would like to store \myvalue{this} and \myvalue{these} and even \myvalue{that}.\par}
% Repeating values...
\def\myvalue#1{{\color{red}#1}}
Version 1: \mysentence % Show me!
% Storing values...
\def\myvalue#1{\xappto\mystore{#1}{\color{red}\mystore}}
Version 2: \mysentence % Show me!
\end{document}


Storing and re-using blocks externally: Please have a look at the collect package, http://ctan.org/pkg/collect, maybe it will fulfill your needs. If not, we can store TeX code by using I/O operations, let me demonstrate it briefly. After second run of TeX you are loading saved blocks of code.

\documentclass[a4paper]{article}
\pagestyle{empty}
\begin{document}
\def\saveto{mytemp.tex}
\newwrite\myfile
\openout\myfile=\saveto
\def\saveit{Some part I would like to store.}
\saveit % Show it in the first part of the document.
\write\myfile{\saveit} % Store it in the file.
\closeout\myfile \par% Close the file properly.
\end{document}


Note. The content of the generated file mytemp.tex is:

Some part I would like to store.


Nested lists: I can recommend packages like expl3, Can I store sequences in sequences with expl3, LuaTeX, http://luatex.org/, and ConTeXt, http://wiki.contextgarden.net/Main_Page, in general.

I enclose an experiment of mine with storing and deleting a mark according to your presented nested structure. I redefined the \write command in a group. It is working as I wished on a small scale but I wouldn't recommend it as it is poorly tested. It was just an experiment of the day.

\documentclass[a4paper]{article}
\pagestyle{empty}
\begin{document}
\def\XmalX{}
\def\mymark{ XmalX}
\def\myfile{part2.tex}
\newwrite\mywrite
\openout\mywrite=\myfile
\long\def\mycommand#1{
\write\mywrite{#1\string\XmalX}
#1}
Beginning of the paragraph 1\mycommand{To be saved 1\mycommand{To be saved 2\mycommand{To be saved 3\par }}}
Beginning of the paragraph 2\mycommand{To be saved 1\mycommand{To be saved 2\mycommand{To be saved 3}}}\par\medskip
\closeout\mywrite
%\end{document}
% Separating Part 1 from Part 2.
\begingroup
\long\def\write#1\XmalX{}
\IfFileExists{\myfile}{\input{\myfile}}{}
\endgroup
\end{document}


Note. There are many potential improvements and different approaches, well, I was just happy it worked. The content of the part2.tex file is rather ugly:

To be saved 1 \write \mywrite {To be saved 2 \write \mywrite {To be saved 3\par \XmalX} To be saved 3\par \XmalX} To be saved 2 \write \mywrite {To be saved 3\par \XmalX} To be saved 3\par \XmalX
To be saved 2 \write \mywrite {To be saved 3\par \XmalX} To be saved 3\par \XmalX
To be saved 3\par \XmalX
To be saved 1 \write \mywrite {To be saved 2 \write \mywrite {To be saved 3\XmalX} To be saved 3\XmalX} To be saved 2 \write \mywrite {To be saved 3\XmalX} To be saved 3\XmalX
To be saved 2 \write \mywrite {To be saved 3\XmalX} To be saved 3\XmalX
To be saved 3\XmalX


Conclusions:

• I would recommend you to keep structure as simple as possible, it minimizes need for many \ifs, \thens and \fis in the code. It saves energy.

• If there is a chance that you can load a parameter without spaces, instead of \def\mymacro#1{#1} and \mymacro{BlockA} use \def\mymacro#1 {#1} and \mymacro BlockA, it will save you some time writing braces.

• I would try to avoid nested structures, instead of nested marque commands, such as \marque{phi}{ \marque{sem}{ ..., I would prefer \marquephi{} \marquesem{} commands, because you need to define a style for that phi and sec part anyway. It doesn't matter for actual marqueing but it does for storing chunks of code.

• I would try to generate the second part of your book during processing the first part, if it is possible. If you need to rearrange blocks, sort them etc., then you probably need more files or some method how to split one big file afterwards. It can be done.

If you generate something like this in one file:

\movetohis{Block of text HIS}
\movetophi{Block of text PHI}
\movetoest{Block of text EST}
\movetophi{Block of text PHI}
\movetophi{Block of text PHI}
\movetosem{Block of text SEM}


then it is quite easy to process it with or without TeX. In TeX you could load the same file several times and you redefine those commands to your needs (use the command or clear it). I enclose my last example where those commands are redefined at the beginning of each section.

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{filecontents}

\begin{document}
\movetohis{Block of text HIS}
\movetophi{Block of text PHI}
\movetoest{Block of text EST}
\movetophi{Block of text PHI}
\movetophi{Block of text PHI}
\movetosem{Block of text SEM}
\end{filecontents*}

% Setion HIS...
\section{HIS}
\def\movetohis#1{#1} % YES
\def\movetophi#1{}
\def\movetoest#1{}
\def\movetosem#1{}

% Section PHI...
\section{PHI}
\def\movetohis#1{}
\def\movetophi#1{#1} % YES
\def\movetoest#1{}
\def\movetosem#1{}

% Section EST...
\section{EST}
\def\movetohis#1{}
\def\movetophi#1{}
\def\movetoest#1{#1} % YES
\def\movetosem#1{}