redefining \ref command to avoid \textit

Changing \ref is not really recommended. Change \p@section and \p@subsection rather, by gobbling \thesection and \thesubsection first and switching back to \normalfont within a group.

Of course, this will be tricky if there are other references to be done.

This is similar to my answer I provided here!

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{lipsum}

\newtheorem{remark}{Remark}

\makeatletter
\def\gobblesomething#1\csname thesection\endcsname{\begingroup\normalfont\S\thesection\endgroup}
\def\gobblesomethingother#1\csname thesubsection\endcsname{\begingroup\normalfont\P\thesubsection\endgroup}
\renewcommand{\p@section}{\gobblesomething}
\renewcommand{\p@subsection}{\gobblesomethingother}

\makeatother

\begin{document}

\section{A}

\lipsum[1]

\subsection{A.1}
\label{a}

\lipsum[2]

\subsection{A.2}

\begin{remark} \label{b}
See \ref{a} \lipsum[2]
\end{remark}

And what about \ref{a} or \ref{b}?
\end{document}

A similar question is this one: Reference appendix objects within texts as 'A. 1', but not 'Appendix A. 1'


It makes sense to redefine the internal \@setref to always choose upshape:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{etoolbox}

\usepackage{lipsum}

\newtheorem{remark}{Remark}

\makeatletter
\patchcmd{\@setref}{\expandafter#2#1}{\textup{\expandafter#2#1}}{}{}
\renewcommand*{\p@section}{\S}% Add section symbol to section reference
\renewcommand*{\p@subsection}{\P}
\makeatother

\begin{document}

\section{A}\label{b}

\lipsum[1]

\subsection{A.1}
\label{a}

\lipsum[2]

\subsection{A.2}

\begin{remark}
See \ref{a} and \ref{b} \lipsum[2]
\end{remark}

\end{document}

enter image description here

If hyperref is needed, the patches are a bit more complicated.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{hyperref}

\usepackage{lipsum}

\newtheorem{remark}{Remark}

\makeatletter
\catcode`#=12
\AtBeginDocument{%
  \patchcmd{\@setref}
    {\expandafter\Hy@setref@link#1\@empty\@empty\@nil{#2}}
    {\textup{\expandafter\Hy@setref@link#1\@empty\@empty\@nil{#2}}}
    {}{}%
}
\catcode`#=6
\patchcmd{\real@setref}{\expandafter#2#1}{\textup{\expandafter#2#1}}{}{}
\renewcommand*{\p@section}{\S}% Add section symbol to section reference
\renewcommand*{\p@subsection}{\P}
\makeatother

\begin{document}

\section{A}\label{b}

\lipsum[1]

\subsection{A.1}
\label{a}

\lipsum[2]

\subsection{A.2}

\begin{remark}
See \ref{a} and \ref{b} \lipsum[2]
\end{remark}

\end{document}

If you only need to remove the italics from \ref you can define an \upshape version of \ref, like this:

\let\refBKP\ref
\renewcommand{\ref}[1]{{\upshape\refBKP{#1}}}

Then all your \ref commands will no longer be italicized.