0

I am trying to write a bash script that gives a tex output for latex beamer. To do so I need to add multiple cat << EOF (or something similar) after one another. First one should be the first page of the presentation so it comes before the loop. Then there are two nested loops to give multiple pages of the presentation. Finally there are some lines to conclude the latex structure such as \end{document} etc. First page and the last lines are not that crucial but writing the main pages of the slides with loops is crucial to me. But it always chooses the last element of the loops.

Here is a short version my attempt. In the original version, the arrays have more elements than those.

#!/bin/bash                                                                                                                                                                                                 

declare -a arrReg=(CR1 CR2)
declare -a arrVar=(pt_el pt_mu)
declare -a arrVarTitle=("electron $p_T$" "muon $p_T$")

laTeXfile=slides.tex

cat > ${laTeXfile}<<EOF                                                                                                                                                                                     
\documentclass{beamer}                                                                                                                                                                                      
\usepackage{graphicx}                                                                                                                                                      
\usepackage[font=small,labelfont=bf]{caption}                                                                           

\begin{document}                                                                                                                                                                                            

%TITLE PAGE  
<<text here>>                                                                                                                                                                                                                                                                                                                                                
EOF                                                                                                                                                                                                         

for i in "${arrReg[@]}"
do
    cnt=0

    for j in "${arrVar[@]}"
    do

        #var=${j}                                                                                                                                                                                           
        varTitle=${arrVarTitle[cnt]}

        cat >${laTeXfile} <<EOF                                                                                                                                                                             
%---------------SLIDE                                                                                                                                                                                       
\begin{frame}  

<<text here>>
\frametitle{${i}}                                                                                                                                                                                           
\framesubtitle{${varTitle}}                                                                                                                                                                                 

\begin{columns} 
<<text here>>   

\end{columns}                                                                                                                                                                                               
\end{frame}                                                                                                                                                                                                 
EOF                                                                                                                                                                                                         

     (( cnt++ ))
    done                                                                                                                                                                                                
done                                                                                                                                                                               

cat > ${laTeXfile}<<EOF                                                                                                                                                                                    
\end{document}                                                                                                                                                                                             
EOF            

Thank you.

mrq
  • 274
  • 1
  • 2
  • 14
  • could you check the beginning of the question please? – mrq Oct 23 '18 at 22:20
  • my main issue is to add multiple cat << EOF to a text file. I removed the other. – mrq Oct 23 '18 at 22:22
  • I'd appreciate if you can remove the duplicate tag. – mrq Oct 23 '18 at 22:28
  • 1
    So your problem is that you are overwriting the file you just created? Use `>>` instead of `>` to append to an existing file. This is hardly worth reopening the question for. In the future, maybe try to reduce your problem to a [mcve]. – tripleee Oct 24 '18 at 04:21
  • 1
    I added a third duplicate which has more details about this. – tripleee Oct 24 '18 at 04:22
  • 1
    you are overwriting your output on every loop step `cat >${laTeXfile}` – JGK Oct 24 '18 at 08:08

0 Answers0