Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luamath parser doesn't support /pgf/number format/read comma as period #1263

Open
muzimuzhi opened this issue Jun 7, 2023 · 0 comments
Open

Comments

@muzimuzhi
Copy link
Member

muzimuzhi commented Jun 7, 2023

Brief outline of the bug

The luamath math expression parser always uses period . as decimal point, thus it fails (silently) when being used to parse a single number with setting /pgf/number format/read comma as period=true.

-- Valid positive decimals are |xxx.xxx|, |.xxx| and |xxx.|
local positive_integer_or_decimal_pattern = positive_integer_pattern * ( P(".") * one_digit_pattern^0)^-1 +
(P(".") * one_digit_pattern^1)

This makes luamath not a drop-in replacement for pgfmath plus fpu library, and result in inconsistent behaviors under LuaTeX and non-LuaTeX engines, see for example pgf-tikz/pgfplots#452.

It seems luamath should re-bind its own \pgfmathfloatparsenumber.

Minimal working example (MWE)

% !TeX program = lualatex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{luamath}

\begin{document}
\pgfset{number format/read comma as period}

\pgfmathfloatparsenumber{1234,56}\pgfmathresult

\pgfset{luamath/parser and computation}
\pgfmathfloatparsenumber{1234,56}\pgfmathresult % works because of the fallback

\directlua{pgfluamathparser.texCallParser("1234,56"), ,true}\pgfmathresult
\end{document}

The direct call of pgfluamathparser.texCallParser("1234,56"), ,true throws error

))[\directlua]:1: syntax error near ','.
l.21 ...amathparser.texCallParser("1234,56"), ,true}
                                                  \pgfmathresult
The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.

The logic of fallback is mentioned in lines 537--538 and implemented in lines 549--544 below

% Parses the math expression and defines \pgfmathresult and
% \ifpgfmathunitsdeclared to contain the result.
%
% If \ifpgfluamathparseractive then the result is also assigned to
% \pgfmathresult. Furthermore, if the expression cannot be evaluated (because LUA does not support
% it), it will be evaluated by mean of TeX as fallback.
%
% @see \ifpgfluamathusedTeXfallback
% @see \ifpgfluamathshowerrormessage
\def\pgfluamathparse#1{%
\pgfluamathusedTeXfallbackfalse
\pgfutil@directlua{pgfluamathparser.texCallParser(
"\pgfutil@luaescapestring{#1}",
\pgfluamath@outputformat@choice,
\ifpgfluamathshowerrormessage true\else false\fi)%
}%
\ifx\pgfmathresult\pgfutil@empty
\ifpgfluamathenableTeXfallback
\pgfluamathusedTeXfallbacktrue
\pgfluamath@pgfmathparse{#1}%
\fi
\fi
}%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant