I'm using Pandoc to convert a LaTeX file of a play to markdown. Pandoc unfortunately does not treat the specialized backslash commands used by the Dramatist package properly, eliminating all of the dialogue.
To get around this problem, I wrote a bash script to pre-process the LaTeX text file.
I'm having a peculiar problem with the use of sed to change a backslash-charactername combination to an upper-case version of the charactername. For example, I want this line:
\direct{\Benjamin goes to the door and lets \Noah in}
to be converted to:
\direct{BENJAMIN goes to the door and lets NOAH in}
As I am producing a book of twelve plays, there are over a hundred character names all told. My bash script reads the character names from a file and uses variable substitution to change each character name from its backslash proper case version to a non-backslashed upper-case version. When I test the sed line in a CLI environment, it works; when I test it in the script it doesn't.
If I type these lines in a CLI environment it works:
Code:
Input_File="Test.tex"
Character="Benjamin"
Upper_Case_Character="${Character^^}"
cat "${Input_File}" | sed "s/\\\\${Character}/${Upper_Case_Character}/g"
If I write a script with this code, it doesn't work.
Code:
Input_File="Test.tex"
while IFS="" read Character; do
Upper_Case_Character="${Character^^}"
cat "${Input_File}" | sed "s/\\\\${Character}/${Upper_Case_Character}/g"
done < "${Char_File}"
I've tried increasing the number of backslashes to no avail.
Here is the contents of the file
Test.tex:
Code:
\documentclass{article}
\usepackage[lnps]{dramatist}
\title{Sample Play}
\author{Peter Freeman}
\date{\today}
\begin{document}
\maketitle
\Character[\Noah{} -- Noah is a gangling teenager.]{Noah}{Noah}
\Character[\Benjamin{} -- Benjamin is a solidly built teen.]{Benjamin}{Benjamin}
\DramPer
\act
\scene
\StageDir{\Benjamin's bedroom is part of a recreational basement.}
\begin{drama}
\speaker{Noah} Whatcha doin', Benj?
\direct{\Noah walks into \Benjamin's basement bedroom.}
\direct{\Benjamin looks up over the smudged pair of glasses he always wears when reading.}
\speaker{Benjamin} I'm figuring out how to build a time machine.
\direct{\Noah throws himself down on an old bean bag that sits against the wall opposite \Benjamin's desk.}
\speaker{Benjamin} Yeah\ldots{}but that's sus. They don't really figure it out properly. There's rules.
\direct{\Benjamin uses his pencil to emphasize his point.}
\speaker{Noah} Sure. You gotta make sure you don't change things, right?
\end{drama}
\end{document}
Thank you,
Peter