Change TeXForm of ArcTan

Using the code from my answer to Format and TeXForm does not work as expected (which I include at the bottom of this answer:

Format[ArcTan[x_], TeXForm] := arctan[x]

Then:

1 + ArcTan[x] //TeXForm

$\arctan (x)+1$

Here is the code:

Initial /: Verbatim[TagSetDelayed][Initial[sym_], lhs_, rhs_] := With[
    {
    new = Block[{sym},
        TagSetDelayed[sym, lhs, rhs];
        First @ Language`ExtendedDefinition[sym]
    ],
    protect = Unprotect[sym]
    },

    sym;
    Replace[new,
        Rule[values_, n:Except[{}]] :> (
            values[sym] = DeleteDuplicates@Join[n, values[sym]]
        ),
        {2}
    ];
    Protect@protect;
]

Initial[Convert`TeX`ExpressionToTeX] /: 
    Convert`TeX`ExpressionToTeX[e__] /; !TrueQ@$TeX := Block[
	{$TeX = True},
        Convert`TeX`ExpressionToTeX[e]
    ]

Initial[Format] /: TagSetDelayed[sym_Symbol, Verbatim[Format][x_, TeXForm], rhs_] := With[
    {fmt = TraditionalForm},

    Initial[sym] /: MakeBoxes[x, fmt] /; $TeX := MakeBoxes[rhs, fmt]
]

Initial[Format] /: SetDelayed[Verbatim[Format][x_, TeXForm], rhs_] := With[
    {s = getTagSymbol[Format[x, TeXForm]], fmt = TraditionalForm},
    Replace[s,
        HoldForm[tag_] :> (
            Initial[tag] /: MakeBoxes[x, fmt] /; $TeX := MakeBoxes[rhs, fmt]
        )
    ]
]

SetAttributes[getTagSymbol, HoldFirst]

getTagSymbol[Format[x_, TeXForm]] := Module[{dummy, t},
    extractTag[Hold[Message[Format::tag, HoldForm@Format, _, tag_], False]] := t = tag;
    Internal`HandlerBlock[{Message, extractTag},
        Quiet[dummy[1] /: Format[x, TeXForm] := 1]
    ];
    t
]

System`Convert`TeXFormDump`maketex[s_String] /; !StringMatchQ[s, "\""~~___~~"\""] && SyntaxQ[s, TeXForm] := Replace[
    s,
    {
        n_ /; StringMatchQ[n, NumberString] :> n,
        w_?wordQ :> "\\operatorname{"<>w<>"}"
    }
]

wordQ[s_String] := Length @ StringSplit[s, WordBoundary] == 1

Usually the simplest methods tend to be the best. Try the code

expr = ArcTan[x/y] - ArcTan[z/w];
StringReplace[ToString[expr, TeXForm], "\\tan ^{-1}" -> "\\arctan"]

which returns

\arctan\left(\frac{x}{y}\right)-\arctan\left(\frac{z}{w}\right)

and in display form is

$$ \arctan\left(\frac{x}{y}\right)-\arctan\left(\frac{z}{w}\right) $$

Tags:

Format

Latex