I have been meaning to mention that we'll also need to orth the contents of <ref>s inside <xr>s.
1) Here is the rule for word-initial i-insertion in orthing:
Where "C" equals any of the following consonants: ʔ c c̣ cʼ h ḥ ḥʷ k kʼ kʷ kʼʷ l ḷ lˀ ḷˀ ɬ ƛʼ m mˀ n nˀ p pʼ q qʼ qʷ qʼʷ r rˀ s ṣ t tʼ w wˀ x xʷ x̣ x̣ʷ y yˀ ʕ ʕˀ ʕʷ ʕˀʷ.
and "V" equals any of the following vowels: á, a, í, i, ú, u, ə́, ə.
and a "word" in a phr is defined as a string preceded by > or whitespace, ignoring any morpheme delimiters,
IF a pron:seg type="p" begins with the string CyV,
OR IF a phr type="p" contains a word which begins with the string CyV,
OR IF a ref begins with the string CyV,
THEN add an i before the y when generating the orth.
I think this is pretty straightforward, although there are then some contexts we'll have to find, check and manually correct: CyV when not word-initial, other Cy and Cw sequences, word-initial šyC sequences, and auto-orthed šiyV sequences.
2) Also, here is the final rule re: removing more stress marks in orths: "If there is only one vowel in a word, remove all stress marks from the word."
Here's my attempt to state it as an algorithm:
Where "V" equals any of the following vowels: á, a, áa, aa, í, i, íi, ii, ú, u, úu, uu, ə́, ə, ə́ə, əə.
IF a pron:seg type="p" contains only one V
OR IF a word (delimited by > and whitespace, or whitespace and <, or whitespace and whitespace, ignoring any morpheme delimiters) within a phr:seg type="p" contains only one V
OR IF a ref contains only one V
THEN replace the following when generating the orth:
á with a
í with i
ú with u
ə́ with ə