Robert Csapo Robert Csapo - 3 months ago 13
LaTeX Question

Enclose paragraphs containing string by text

I have got a long bibliography file created for use in a .tex file and would like to modify it such that my own citations appear in bold face. This could be manually achieved by enclosing each bibliography item (separated by blank lines) containing my name (let's assume it is Crowe) with \textbf{}.

Is there any way I could automate this process? Maybe using awk? Below is a short example of my original text and the way I'd like it to be modified (note the \textbf{ preceding the second bib item and the closing } at the end).

Thank you for your help!
Robert

%---- ORIGINAL FILE ----%

\begin{thebibliography}{}

\bibitem [\protect \citeauthoryear {%
Aagaard%
\ \BBA {} Andersen%
}{%
Aagaard%
\ \BBA {} Andersen%
}{%
{\protect \APACyear {1998}}%
}]{%
Aagaard:1998aa}
\APACinsertmetastar {%
Aagaard:1998aa}%
\begin{APACrefauthors}%
Aagaard, P.%
\BCBT {}\ \BBA {} Andersen, J\BPBI L.%
\end{APACrefauthors}%
\unskip\
\newblock
\APACrefYearMonthDay{1998}{Aug}{}.
\newblock
{\BBOQ}\APACrefatitle {Correlation between contractile strength and myosin
heavy chain isoform composition in human skeletal muscle} {Correlation
between contractile strength and myosin heavy chain isoform composition in
human skeletal muscle}.{\BBCQ}
\newblock
\APACjournalVolNumPages{Med Sci Sports Exerc}{30}{8}{1217-22}.
\PrintBackRefs{\CurrentBib}

\bibitem [\protect \citeauthoryear {%
Young%
, Stokes%
\BCBL {}\ \BBA {} Crowe%
}{%
Young%
\ \protect \BOthers {.}}{%
{\protect \APACyear {1985}}%
}]{%
Young:1985aa}
\APACinsertmetastar {%
Young:1985aa}%
\begin{APACrefauthors}%
Young, A.%
, Stokes, M.%
\BCBL {}\ \BBA {} Crowe, M.%
\end{APACrefauthors}%
\unskip\
\newblock
\APACrefYearMonthDay{1985}{Apr}{}.
\newblock
{\BBOQ}\APACrefatitle {The size and strength of the quadriceps muscles of old
and young men} {The size and strength of the quadriceps muscles of old and
young men}.{\BBCQ}
\newblock
\APACjournalVolNumPages{Clin Physiol}{5}{2}{145-54}.
\PrintBackRefs{\CurrentBib}

\end{the bibliography}


.

%---- MODIFIED FILE ----%

\begin{thebibliography}{}

\bibitem [\protect \citeauthoryear {%
Aagaard%
\ \BBA {} Andersen%
}{%
Aagaard%
\ \BBA {} Andersen%
}{%
{\protect \APACyear {1998}}%
}]{%
Aagaard:1998aa}
\APACinsertmetastar {%
Aagaard:1998aa}%
\begin{APACrefauthors}%
Aagaard, P.%
\BCBT {}\ \BBA {} Andersen, J\BPBI L.%
\end{APACrefauthors}%
\unskip\
\newblock
\APACrefYearMonthDay{1998}{Aug}{}.
\newblock
{\BBOQ}\APACrefatitle {Correlation between contractile strength and myosin
heavy chain isoform composition in human skeletal muscle} {Correlation
between contractile strength and myosin heavy chain isoform composition in
human skeletal muscle}.{\BBCQ}
\newblock
\APACjournalVolNumPages{Med Sci Sports Exerc}{30}{8}{1217-22}.
\PrintBackRefs{\CurrentBib}

\textbf{\bibitem [\protect \citeauthoryear {%
Young%
, Stokes%
\BCBL {}\ \BBA {} Crowe%
}{%
Young%
\ \protect \BOthers {.}}{%
{\protect \APACyear {1985}}%
}]{%
Young:1985aa}
\APACinsertmetastar {%
Young:1985aa}%
\begin{APACrefauthors}%
Young, A.%
, Stokes, M.%
\BCBL {}\ \BBA {} Crowe, M.%
\end{APACrefauthors}%
\unskip\
\newblock
\APACrefYearMonthDay{1985}{Apr}{}.
\newblock
{\BBOQ}\APACrefatitle {The size and strength of the quadriceps muscles of old
and young men} {The size and strength of the quadriceps muscles of old and
young men}.{\BBCQ}
\newblock
\APACjournalVolNumPages{Clin Physiol}{5}{2}{145-54}.
\PrintBackRefs{\CurrentBib}}

\end{the bibliography}

Answer

awk to the rescue! I think you have markup problems but this will do the bold wrapping

$ awk -v RS= -v ORS="\n\n" '/bibitem/ && /Crowe/{print "\\textbf{" $0 "}"; next}1' file

if there are false positives, you can fine tune pattern matching.

Explanation

-v RS= sets the paragraph mode, records separated by one or more blank lines

ORS="\n\n" normalizes output with a blank line in between records

/bibitem/ && /Crowe/ if these two patterns found in the record ...

print "\\textbf{" $0 "}"; next wrap the current record ($0) with prefix and suffix quoted and skip to next record

1 print the records as is

Comments