Recovering my knowledge of LaTex long gone, would appreciate your help on how to achieve raggedleft or raggedrigh justification on margin captions depending on the page we are. I think it is probably not that easy as I was thinking and there is some dependency on the information latex has when laying out the pages, but not sure. Please check the example below
\documentclass[twoside]{scrartcl}
\usepackage[outer=7cm, inner=3cm, marginparwidth=4cm, marginparsep=10mm]{geometry}
\usepackage[top]{mcaption}
\usepackage[font=footnotesize,normal]{caption}
\usepackage{graphicx}
\usepackage{mwe}
\DeclareCaptionJustification{raggedauto}{\ifodd\thepage \raggedright \else \raggedleft \fi}
\captionsetup{labelfont={bf}, font={it,footnotesize}, justification=raggedauto, singlelinecheck=false, position=above}
\begin{document}
\begin{figure}[htb]
\begin{margincap}
\caption{This is my caption}
\includegraphics[width=\textwidth]{example-image-a}
\end{margincap}
\end{figure}
\begin{figure}[htb]
\begin{margincap}
\caption{This is my caption}
\includegraphics[width=\textwidth]{example-image-b}
\end{margincap}
\end{figure}
\newpage
\begin{figure}[htb]
\begin{margincap}
\caption{This is my caption}
\includegraphics[width=\textwidth]{example-image-c}
\end{margincap}
\end{figure}
\end{document}
and
As you can see I only have the right effect I want on C, because I forced a \newpage. On my original files, other types of sections also seem to reset "the page side" correctly. What can I change to correct picture B automatically? Thanks