Since you want to do an assignment, expandability is not a factor.
The simplest method is to define a suitable command, say
\setlengthfromfile{<length>}{<file>}{<expression>}
where <length> is the register you want to set, <file> is the file you want to read a value from and <expression> contains #1 to denote the file contents, so your case would be
\setlengthfromfile{\parskip}{data.txt}{1pt * #1}
Code with examples:
\begin{filecontents*}{\jobname.dat}
20
\end{filecontents*}
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\setlengthfromfile}{mmm}
{% #1 = length parameter
% #2 = file name
% #3 = expression
\yegor_setlengthfromfile:nnn { #1 } { #2 } { #3 }
}
\cs_new:Nn __yegor_setlengthfromfile_aux:n { } % initialize
\cs_generate_variant:Nn __yegor_setlengthfromfile_aux:n { V }
\tl_new:N \l__yegor_setlengthfromfile_tl
\cs_new_protected:Nn \yegor_setlengthfromfile:nnn
{
\file_get:nnN { #2 } { } \l__yegor_setlengthfromfile_tl
\cs_set:Nn __yegor_setlengthfromfile_aux:n { #3 }
\skip_set:Nn #1 { __yegor_setlengthfromfile_aux:V \l__yegor_setlengthfromfile_tl }
}
\ExplSyntaxOff
\setlengthfromfile{\parskip}{\jobname.dat}{1pt * #1}
\showthe\parskip
\setlengthfromfile{\parskip}{\jobname.dat}{1pt * #1-12pt}
\showthe\parskip
\setlengthfromfile{\parskip}{\jobname.dat}{#1\parskip}
\showthe\parskip
\setlengthfromfile{\parskip}{\jobname.dat}{#1pt plus 0.1pt}
\showthe\parskip
\stop
The console will show
(./yegordim.dat
)
> 20.0pt.
l.31 \showthe\parskip
?
(./yegordim.dat)
> 8.0pt.
l.34 \showthe\parskip
?
(./yegordim.dat)
> 160.0pt.
l.37 \showthe\parskip
?
(./yegordim.dat)
> 20.0pt plus 0.1pt.
l.40 \showthe\parskip
In the third example we reused the previous value of \parskip.
\input– plante Jan 03 '22 at 09:20\xin the end, which I can use in calculations of lengths. – yegor256 Jan 03 '22 at 09:45\CatchFileDefmethod I suggested? If you plan to use\xseveral times, it allows to read the file just once. Of course, in this case, I'd not call the value\x, but use a more descriptive name. – egreg Jan 03 '22 at 10:20\xas often as you want, why do you need to read the same file multiple times??? – David Carlisle Jan 03 '22 at 11:43