My LaTeX-out.tex TeX Code is (single line):
\begin{align*}\alpha + \beta = \gamma\end{align*} Some text here. \begin{align*}\sum^{k}_{i=1} \iota \end{align*} and so on the text. \begin{thebibliography}{000}\bibitem{cqgab7bbabib1}{Aasi J et al LIGO Scientific and VIRGO Collaborations 2014 Constraints on cosmic strings from the LIGO-Virgo gravitational-wave detectors.} \bibitem{cqgab7bbabib2}{Abbott B P et al LIGO and Virgo Collaborations 2016 Astrophysical implications of the binary black hole merger GW150914 L22} \bibitem{cqgab7bbabib3}{Abbott B P et al LIGO and Virgo Scientific Collaboration 2016 Search for transient gravitational waves in coincidence with short duration radio transients during 2007–2013}. \bibitem{cqgab7bbabib4}{Abbott B P et al The LIGO Scientific and Virgo Collaborations 2018 GWTC-1: a gravitational-wave transient catalog of compact binary.}
My Lua Code is (i would like enter(\n) before \begin and enter(\n) before \bibitem):
local file = io.open("LaTeX-out.tex")
local fileedited = io.open("LaTeX-Updated.tex", "w")
local content = file:read "*a"
file:close()
contentmodified = string.gsub(content, [[\begin]], [[\n\begin]])
contentmodified = string.gsub(content, [[\end]], [[\n\end]])
contentmodified = string.gsub(content, [[\bibitem]], [[\n\bibitem]])
contentmodified = string.gsub(content, [[(\begin or \end)]], [[\n%1]])--it's not working **or**
fileedited:write(contentmodified)
fileedited:close()
But it's taking only final find and replace only (like \bibitem) and ignoring \begin and \end. How do solve this?
\n?[[\n\bibitem]]note\nand\bhave the same level of quoting here, – David Carlisle Oct 31 '20 at 17:53\bin\beginmeans literally\bthen the\nin the same string means literally\nnot a newline. See the version in my answer where\nand\bare quoted differently. – David Carlisle Oct 31 '20 at 18:04