1

I am using an add-on to Stata in order to generate Latex-Tables that show estimation results and significance levels for some models.

On of these programs creates table of the following form, which I then input in another document using the expl3 package. I present an adapted MWE of this file, which I call mwe2.tex:

\begin{tabular}{ccc}\hline
line 1  &   a  &  b  \\ \hline
main    &      &     \\ \hline
x       &   y  &  z  \\ \hline
\end{tabular}

For some reason, there is a row included that contains only the term "main" and is empty otherwise. This needs to be deleted. Now comes the actual file that I can edit and work with (whereas the above code is given). I input the above code via the following:

\documentclass[12pt]{scrartcl}

\usepackage{l3regex}
\usepackage{xparse}
\ExplSyntaxOn
\ior_new:N \l_marie_input_stream 
\NewDocumentCommand{\SearchAndReplace}{mmm}{%
  \ior_open:Nn \l_marie_input_stream {#1}% Open the file
  \ior_map_inline:Nn \l_marie_input_stream {% Read line by line
    \tl_set:Nn \l_tmpa_tl {##1}% Store the line 
    \regex_replace_all:nnN {#2} {#3} \l_tmpa_tl % Replace #2 by #3
    \tl_use:N \l_tmpa_tl % Display the (modified) line content
  }
  \ior_close:N \l_marie_input_stream % close the file
}
\ExplSyntaxOff

\begin{document}
abc\\

\SearchAndReplace{mwe2}{main}{maaaain}

def
\end{document}

![The problem

Following the solution in this question, I input the file while replacing the term main with something else, but not with %main, because then the compilation gives an error.

I tried to replace the complete line with an empty space, i.e.

\SearchAndReplace{mwe2}{main&  &   \\}{ }

But this does not work--nothing changes. I precisely copied the content of the whole above line into the "replace-box" in the other document, but to no avail.

My second idea is to replace simply the work main with , which works fine, but leaves me with an empty line in the document:

\SearchAndReplace{mwe2}{main}{ }

enter image description here

My plan is now to replace main with some other code that allows me to set the height of the row in the table to 0. In this way, I would have a work-around that virtually removes the unnecessary line, by removing the content and setting its height to zero. However, I did some research, yet cannot find a command in latex that can be used to define the height of a single, specific row to be zero.

  • 1
    Why don't you just skip the line if it contains "main" in expl3 (sure there is a way to do it...). I tried to substitute with \relax to avoid the \par given by the white line, but to no avail, and I am not versed in expl3 syntax. – Rmano Feb 1 '16 at 20:39
3

Being not versed in expl3, I would rater use a shell escape in this case. You have to adapt this to your operating system, but on Unix-like is quite simple; let this file being main.tex:

\documentclass[12pt]{scrartcl}
\begin{document}
abc

\input{|"grep -v ^main mwe2.tex"}

def
\end{document}

...and then run it with pdflatex --shell-escape main-tex

The command

grep -v ^main file

outputs all the lines in file that do not (-v) start (^) with the word "main", and the result is input into LaTeX which will never see the line starting with "main".

Result:

Result with shell escape

NOTICE The following old answer here is for the first version of the question, that was completely different....

Hmmm... putting an % (comment) before "main" works here. (for little value of "work" --- you should really edit your code snippet so that it is compilable, with all the packages and option you load which probably do the difference).

\documentclass{article}
\begin{document}

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{6}{c}}
\hline\hline
            &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}\\
            &\multicolumn{1}{c}{collage}&\multicolumn{1}{c}{big}&\multicolumn{1}{c}{small}&\multicolumn{1}{c}{together}&\multicolumn{1}{c}{separated}&\multicolumn{1}{c}{nophoto}\\
\hline
%main        &                     &                     &                     &                     &                     &                     \\
\(N\)       &         798         &         791         &         803         &         803         &         798         &         435         \\
\hline\hline
\end{tabular}
}

Result

| improve this answer | |
  • I actually did not think of that, but I tried it and it did not work. Following your suggestion, I have now adapted my code and given an MWE to show the problem. Thank you for your effort! – Marie. P. Feb 1 '16 at 20:27
  • 1
    Ups, now it's a completely different problem... I suggest you to add expl3 tag and explicitly say it in the text. – Rmano Feb 1 '16 at 20:36

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.