Question: I have a list:

```
\begin{enumerate}[label={[\Roman*]},ref={[\Roman*]}]

\item\label{item1} The first item.

\end{enumerate}

```

What I want to achieve is this: 

In the most instances, I want to refer to the items of the list by the format specified above (that is: `\ref{item1}` should in general produce "[I]"). However, in a few particular instances, I want to refer to the items by a custom reference formatting (more specifically, without the square brackets, by "1" instead of "[1]"), but I want still that the numbering is automatic (otherwise, I could use, for example `\hyperref[item1]{1}` to refer). Therefore, I would like to, for example, define a new command `\nobracketsref` such that `\nobracketsref{item1}` should produces "1".

How this could be achieved? I would appreciate any help.

PS. In the situation there is one twist that may affect the solution: I have two `.tex` files so that the list is in one file (the list document) and I am referring to its items from the other file (the main document). 

This is done in a usual way by involving in the preamble of the main document:

```
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument{the_list_document.tex}

```

Answer: 
Define `ref=` to use a macro, instead of the explicit brackets; such a macro can be redefined to do nothing when the brackets are not wanted.

```
\documentclass{article}
\usepackage{enumitem,xparse}
\usepackage[colorlinks]{hyperref}

\makeatletter
\NewDocumentCommand{\nobracketref}{sm}{%
  \begingroup\let\bracketref\@firstofone
  \IfBooleanTF{#1}{\ref*{#2}}{\ref{#2}}%
  \endgroup
}
\makeatother
\NewDocumentCommand{\bracketref}{m}{[#1]}

\begin{document}

\begin{enumerate}[label={[\Roman*]},ref={\bracketref{\Roman*}}]
\item\label{item1} The first item.
\end{enumerate}

With brackets: \ref{item1} (link)

With brackets: \ref*{item1} (no link)

Without brackets: \nobracketref{item1} (link)

Without brackets: \nobracketref*{item1} (no link)

\end{document}

```

I don't think `xr-hyper` is much of a concern here.

[![enter image description here](https://i.stack.imgur.com/W0rtE.png)](https://i.stack.imgur.com/W0rtE.png)
Here's a LuaLaTeX-based solution. It sets up a LaTeX macro called `\nobracketref` which, in turn, invokes a Lua function called `nobrackets` which removes the outermost brackets in the function's argument. 

Observe that the Lua function tests whether the cross-reference is valid. If it is not valid, i.e., if `\ref` returns `??` instead of something like `[I]`, `\nobracketref` prints an empty string. Once the cross-reference is resolved correctly, `\nobracketref` will print `I`.

[![enter image description here](https://i.stack.imgur.com/zpd1b.png)](https://i.stack.imgur.com/zpd1b.png)

```
\documentclass{article}
\usepackage{enumitem,luacode}

%% Lua-side code
\begin{luacode}
function nobrackets ( s )
   if string.find ( s , "%?" ) then
      return ""
   else
      s = string.gsub ( s , "%[(.*)%]", "%1" )
      return tex.sprint ( s )
   end
end
\end{luacode}

%% TeX-side code
\newcommand\nobracketref[1]{%
   \directlua{ nobrackets ( \luastring{\ref{#1}} ) }}

\begin{document}

\begin{enumerate}[label={[\Roman*]},ref={[\Roman*]}]
\item\label{item:1} The first item.
\end{enumerate}

Using \texttt{\textbackslash ref}: item \ref{item:1}.

Using \texttt{\textbackslash nobracketref}: item \nobracketref{item:1}.

\end{document}

```

A caveat: This solution is (for now) not compatible with the `hyperref` package. Do let me know if `hyperref` compatibility is a requirement for you.