# Is it possible to flushright the right-hand side with systeme without \hphantom?

I typeset some systems of equations, and I really like the format of input (as well as the output) the systeme package provides.

Now, I wonder if there is a way to flushright also the right-hand side of the equation, without using \hphantom? In the example below, I get the result as I want in the second system, but not the first. But I do it with a \hphantom.

 \documentclass{minimal}
\usepackage{systeme}
\begin{document}
$\systeme{x+y=2,x-y=-2}$
$\systeme{x+y=\hphantom{-}2,x-y=-2}$
\end{document}


giving

Update

Just in case someone wonders why on earth one would like to have the right-hand side flushright, here is an image that might explain it better. Without the right-hand side being flushright, the arrows look bad not ending at the same horizontal location.

Also, I can mention that I have read the documentation of the systeme package, and I did not find anything like this (but my french is rusty). I also browsed the source of the package, but that was too complicated for me...

It's a choice of the package to have the last column aligned left and, as far as I can see, there's no provision for changing it by setting an option.

You can change it by redefining the command \SYS@makesyspreamble@i that's responsible for setting the alignment in columns; the simplest way is to use regexpatch:

\documentclass{article}

\usepackage{systeme}
\usepackage{regexpatch}

\makeatletter
\xpatchcmd{\SYS@makesyspreamble@i}
{$##$\hfil\null}% left alignment
{\hfil$##$\null}% right alignment
{}{}
\makeatother

\begin{document}

$\systeme{x+y=2,x-y=-2}$

\end{document}


Should you need to switch between left and right alignment, here's how to do it.

\documentclass{article}

\usepackage{systeme}
\usepackage{regexpatch}

\makeatletter
\xpatchcmd{\SYS@makesyspreamble@i}
{$##$\hfil\null}
{\span\SYSX@afterequalalignment\null}
{}{}
\newcommand{\SYSX@afterequalalignmentleft}{$##$\hfil}% default
\newcommand{\SYSX@afterequalalignmentright}{\hfil$##$}% default
\newcommand{\rightalignafterequal}{%
\let\SYSX@afterequalalignment\SYSX@afterequalalignmentright
}
\newcommand{\leftalignafterequal}{%
\let\SYSX@afterequalalignment\SYSX@afterequalalignmentleft
}
\leftalignafterequal % default
\makeatother

\begin{document}

$\systeme{x+y=2,x-y=-2}$
\rightalignafterequal \systeme{x+y=2,x-y=-2}

\end{document}


The \rightalignafterequal declaration obeys the usual scoping rules, so you can issue it in the preamble if you want all systems to have right alignment.

## UPDATE

The most recent version of systeme no longer uses @ for private macros, so the patch should be modified.

\documentclass{article}

\usepackage{systeme}
\usepackage{regexpatch}

\chardef\savedunderscorecatcode=\catcode\_
\catcode\_=11
\xpatchcmd{\SYS_makesyspreamble_i}
{$##$\hfil\null}
{\span\SYSX_afterequalalignment\null}
{}{}
\newcommand{\SYSX_afterequalalignmentleft}{$##$\hfil}% default
\newcommand{\SYSX_afterequalalignmentright}{\hfil$##$}% default
\newcommand{\rightalignafterequal}{%
\let\SYSX_afterequalalignment\SYSX_afterequalalignmentright
}
\newcommand{\leftalignafterequal}{%
\let\SYSX_afterequalalignment\SYSX_afterequalalignmentleft
}
\leftalignafterequal % default
\catcode\_=\savedunderscorecatcode

\begin{document}

$\systeme{x+y=2,x-y=-2}$
\rightalignafterequal \systeme{x+y=2,x-y=-2}

\end{document}

• Wonderful! This does exactly what I want (I will wait a while before accepting the answer, since I've been told to do so). – mickep May 26 '15 at 20:20
• Thanks for that update as well! I don't think I will need it, but maybe someone else who stumbles upon this question will. I will mark your answer as accepted, since it really solved my problem. Thanks again! – mickep May 27 '15 at 7:18

I am reviving this old post because systeme has changed so egreg's solution no longer has any effect, because the patched command name has changed.

To right-align the last column for systeme version 0.32, dated 2019/01/13 use:

\makeatletter
\catcode\_11
\xpatchcmd{\SYS_makesyspreamble_i}
{$##$\hfil\null}% left alignment
{\hfil$##$\null}% right alignment
{}{}
\catcode\_8
\makeatother


I hope egreg would be kind enough to update his solution for switching between right and left alignment (and correct my code if necessary).

• I've checked egreg's alignment switching code and all it needs is the line \xpatchcmd{\SYS@makesyspreamble@i} replaced by \catcode_11 \xpatchcmd{\SYS_makesyspreamble_i}. Not sure if it also should have \catcode\_8` at the end. – stevem Dec 3 '19 at 17:14