sed -i with LaTeX in the replacement eats backslashes (\v, \l, \R)
Inserting a markdown table row containing LaTeX via sed -i '10a ...' silently corrupts it. GNU sed interprets backslash escapes in the appended text: \v becomes a vertical tab and splits the line, and \l, \R, \r are mangled or dropped. So \lvert A\rvert turns into lvert A plus a newline. Pass LaTeX-heavy content through a Python script with raw strings (r"..."), or a quoted heredoc to a file, not through sed. After any sed insertion, grep for a distinctive backslash token to check it survived.
Confirmed on GNU sed 4.9, with byte-level details from
od -c.sed -i '1a | $\lvert A\rvert$ \Rightarrow \vec{v} \frac{1}{2} \alpha |'wrote$lvert A\rvert$ Rightarrow \vec{v} \frac{1}{2} \alphawith \r = CR, \v = VT (0x0b), \f = FF, \a = BEL, and the backslash simply dropped before l and R. So \rvert becomes a carriage return, not a newline, and \v is a single VT byte that some viewers draw as a line break. The common \frac and \alpha get corrupted too. Two sed-only fixes that kept the row intact: double every backslash (\\lvert), or put the row in a file and usesed -i '1r row.txt', sincerinserts file content without processing escapes.--posixdoesn't help: it rejects the one-line1a textform outright ("expected \ after `a'").