As this thread has come back, I'd like to take the time to say thank you.
Tisza Gergő wrote:
Just put the templates on separate lines and wrap the whole thing in another #if to discard additional newlines at the end:
{{#if:1| {{{{{subst|}}}#if:{{{par1|1}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if: {{{key1|1}}}|{{{{{subst|}}}!}}{{{key1}}}}}]]}} {{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if: {{{key2|}}}|{{{{{subst|}}}!}}{{{key2}}}}}]]}} {{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if: {{{key3|}}}|{{{{{subst|}}}!}}{{{key3}}}}}]]}} }}
(This assumes that whenever par2 is missing, par3 is missing too.)
That worked, and I finally finished the replacements today. For just the categories, I needed 3 levels of those wrapping #if's. Elsewhere, I needed 4 levels.
Fortunately, BBedit on a Mac does a good job keeping track of the levels for balancing {}.
My final code for posterity (aligned, using my emit templates, but not putting the par test in them yet, which could probably be done to make the code cleaner) for just the categories -- see the actual 40+ parameter mess at [[Template:Catdesc wipeout parent categories]]:
{{{{{subst|}}}#if:3 | {{{{{subst|}}}#if:1 | {{{{{subst|}}}#if:{{{par1|}}} |{{{{{subst|}}}emit category |1={{{par1|}}} |2={{{key1|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par2|}}} |{{{{{subst|}}}emit category |1={{{par2|}}} |2={{{key2|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par3|}}} |{{{{{subst|}}}emit category |1={{{par3|}}} |2={{{key3|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par4|}}} |{{{{{subst|}}}emit category |1={{{par4|}}} |2={{{key4|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par5|}}} |{{{{{subst|}}}emit category |1={{{par5|}}} |2={{{key5|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par6|}}} |{{{{{subst|}}}emit category |1={{{par6|}}} |2={{{key6|}}} |subst={{{subst|}}} }} }} }} {{{{{subst|}}}#if:2 | {{{{{subst|}}}#if:1 | {{{{{subst|}}}#if:{{{dpar1|}}} |{{{{{subst|}}}emit category |1={{{dpar1|}}} |2={{{dkey1|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar2|}}} |{{{{{subst|}}}emit category |1={{{dpar2|}}} |2={{{dkey2|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar3|}}} |{{{{{subst|}}}emit category |1={{{dpar3|}}} |2={{{dkey3|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar4|}}} |{{{{{subst|}}}emit category |1={{{dpar4|}}} |2={{{dkey4|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar5|}}} |{{{{{subst|}}}emit category |1={{{dpar5|}}} |2={{{dkey5|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar6|}}} |{{{{{subst|}}}emit category |1={{{dpar6|}}} |2={{{dkey6|}}} |subst={{{subst|}}} }} }} }} {{{{{subst|}}}#if:1 | {{{{{subst|}}}#if:{{{epar1|}}} |{{{{{subst|}}}emit category |1={{{epar1|}}} |2={{{ekey1|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar2|}}} |{{{{{subst|}}}emit category |1={{{epar2|}}} |2={{{ekey2|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar3|}}} |{{{{{subst|}}}emit category |1={{{epar3|}}} |2={{{ekey3|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar4|}}} |{{{{{subst|}}}emit category |1={{{epar4|}}} |2={{{ekey4|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar5|}}} |{{{{{subst|}}}emit category |1={{{epar5|}}} |2={{{ekey5|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar6|}}} |{{{{{subst|}}}emit category |1={{{epar6|}}} |2={{{ekey6|}}} |subst={{{subst|}}} }} }} }} }} }}