I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:
Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?
A minimum working example is:
\documentclass{article}
\newenvironment{varlength}{
\begin{center}
\rule{0.9\textwidth}{0.8pt}
\begin{minipage}{0.6\textwidth}}{
\end{minipage}
\end{center}}
\begin{document}
\begin{varlength}
This is a text inside fixed length minipage with over-line
I want the same to be repeated for variable width box
\end{varlength}
\end{document}


varwidthin the answers to the question marked as duplicate. – egreg Dec 01 '18 at 16:13