esami LaTeX 包中的 \FPsignpol 命令

esami LaTeX 包中的 \FPsignpol 命令

LaTeX 软件包esami可让您轻松准备考试。\FPsignpol下面定义的命令用于根据参数编写多项式系数。它基于软件包\FPval中的命令\fp

{\FPval\tempsign{#1}
\ifthenelse{\equal{#2}{}}{\ifnum \tempsign<0 {\sempli{\tempsign}{1}#2}\else \ifnum \tempsign>0{+\sempli{\tempsign}{1}#2}\else{}\fi\fi}
{\ifnum \tempsign<0 {\semplix{\tempsign}{1}#2}\else \ifnum \tempsign>0{+\semplix{\tempsign}{1}#2}\else{}\fi\fi}
} 

但是计算系数时,加号/减号离数字太近了。\FPsignpoli下面定义的修改版本改进了正系数时加号和数字之间的间距,但我不知道如何解决负系数的问题。

{\FPval\tempsign{#1}
\ifthenelse{\equal{#2}{}}{\ifnum \tempsign<0 {\,\sempli{\tempsign}{1}#2}\else \ifnum \tempsign>0{\,+\,\sempli{\tempsign}{1}#2}\else{}\fi\fi}
{\ifnum \tempsign<0 {\semplix{\tempsign}{1}#2}\else \ifnum \tempsign>0{\,+\,\semplix{\tempsign}{1}#2}\else{}\fi\fi}
} 

下图提供了两种输出的示例。

在此处输入图片描述

您能帮我解决这个问题吗?提前谢谢您。

这是一个完整的示例,需要 3 个文件:master.tex、esami-xyz.cfg 和本示例中包含的唯一练习的文件 ex.tex。

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = pdflatex
% !TEX root = master3DM-1IQ-2021-22.tex

\documentclass[italian,a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage[text={1550mm,250mm},centering]{geometry}
%\usepackage[a4paper,top=2.5cm,bottom=2.5cm,left=4.1cm,right=2.1cm]{geometry}

\usepackage[shuffle,xyz,autopstoff,solutions]{esami}%%%%% TEMA

\geometry{a4paper,top=1.5cm,bottom=1.5cm,left=1.1cm,right=1.1cm}

\usepackage{float,tikz}

\def\profname{Professor Name}
\def\examname{Data}
\def\numcompiti{1}%%% The number of versions
\date{2021/10/09}%%% THE DATE IN THE FORMAT AAAA/M/D
\def\Data{\longdate}%%% or \shortdate: the date in the heading

\begin{document}
\testversioni
%\pagestyle{esame}
\pagestyle{empty}

\whiledo{\thevers<\numcompiti}{\stepvers
% +=============================+
% |       THE SEED              |
% +=============================+
%\FPeval\seme{round((\thenomefile+(3*\thevers)):0)}
%% OR OTHER SUCH AS
\FPeval\seme{round(\thenomefile*(\thevers)+1-trunc(\thenomefile*(\thevers)/(2^31-1):0)*(2^31-1):0)}
%\FPeval\seme{round(1+abs(\thenomefile/(\thevers)+sin(\thevers)*(\thevers)^(2)):0)}

\randomi=\seme

% +=============================+
% |  STUFF DEFINED IN CFG FILE  |
% +=============================+

%\testa%%% the heading
%\istruzionii%%%  some instructions


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\renewcommand\exlabelformat{{\scshape\exlabel}}



\begin{center}
{\Large \textsc{School name}
\\~\\
\textsc{Test name}}
\\
\end{center}

\esercizi{ex}



\vskip0.5cm
\hrule

\setcounter{ex@no}{0}

\closevers
}
\end{document}
%% Package `esami' to use with LaTeX 2e
%%  Copyright (C) 2008-2013  G. Messineo e S. Vassallo
%%
%% This is file `esami-xyz.cfg',
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% esami-xyz.cfg,             2013-03-20                %%
%% Copyright (C) 2008-2013 G. Messineo e S. Vassallo    %%
%%                                                      %%
%% This program can be redistributed and/or modified    %%
%% under the terms of the LaTeX Project Public License  %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% +=============================+
% |         THE HEADING         |
% +=============================+

 \@ifpackagewith{esami}{prova}{%
 \def\testa{\relax}}
{%
\def\testa{
\setcounter{page}{0}
\thispagestyle{empty}
\begin{center}
~\vskip3cm
{\huge \hskip1cm\textsc{School name}}
\vskip0.8cm
{\huge\hskip1cm\textsc{Test name}}
\vskip0.8cm
{\huge\hskip1cm\textsc{del \underline{~~~~~~~~~~~~~~~}}
}
\end{center}
\vskip0.5cm 

\noindent
\hskip1cm \underline{\textsc{Studente name}: 
\hskip6cm \textsc{Class}: ~~~}%
\vskip0.7mm
\vskip1cm


\vfill\eject

\vskip1cm
\vfill\eject
%   {\bfseries\sffamily\small
%   \begin{center}
%   \begin{tabular}{|lp{.33\textwidth}|lp{.33\textwidth}|lp{.33\textwidth}|}
%   \hline
%   \multicolumn{1}{|p{.33\textwidth}}{\profname }&\multicolumn{1}{|p{.33\textwidth}}   {\examname  } &\multicolumn{1}{|p{.34\textwidth}|}{Classe}\\[3ex]
%   \hline
%   \multicolumn{1}{|p{.33\textwidth}}{Cognome (in stampatello)}&\multicolumn{1}{|p{.   33\textwidth}}{Nome (in stampatello)}&\multicolumn{1}{|p{.34\textwidth}|}{Firma     leggibile}\\[4ex]
%   \hline
%   \end{tabular}\\[3ex]
%   \end{center}}
 }
 }

% +=============================+
% |         THE FOOTER          |
% +=============================+

\ifes@solutions%%%solutions
\def\ps@esame{\let\@oddhead\@empty\def\@oddfoot{\hfil \textbf{\versionname\
n. \thevers} -- %%
\textbf{\solutionsname} --  %%
 \pagename\ \thepage  \hfill  Alunna/o \underline{~~~~~~~~~~~~~~~~~~~~~~~~~~} Classe 3A
\hfil}\let\@evenhead\@empty\let\@evenfoot\@empty}
\else%%% no solutions
    \def\ps@esame{
    \let\@oddhead\@empty\def\@oddfoot%%
    {\hfil  \textbf{\versionname\ n. \thevers\
      -- \pagename\ \thepage  \hfill Alunna/o \underline{~~~~~~~~~~~~~~~~~~~~~~~~~~} Classe 3A}\hfil}
\let\@evenhead\@empty\let\@evenfoot\@empty}
\fi

% +=============================+
% |   THE SOLUTION STRING       |
% +=============================+

\def\ps@soltest{\let\@oddhead\@empty\def\@oddfoot{\hfil %\textbf{\versionname\ n. \thevers} -- %%
\textbf{\solutionsname} -- \pagename\ \thepage
\hfil}\let\@evenhead\@empty\let\@evenfoot\@empty}

\ifes@solutions
\newcommand{\stringasol}{\newpage%
\vspace{.8cm}
\pagestyle{soltest}
 \input{\jobname.sol.tex}                                                                                %
}
\else
\newcommand{\stringasol}{\relax}
\fi


% +=============================+
% |   SOME INTRUCTIONS          |
% +=============================+

\def\istruzionii{{
\sffamily \textbf{ISTRUZIONI}
\begin{itemize}
  \item Il punteggio per chi consegna in bianco \`e di punti 1 su 10.
  \item Non \`e consentito consegnare altri fogli oltre alla presente scheda
  \item La durata della prova \`e di un’ora.
  \item Firmare ogni foglio.
\end{itemize}}}

\def\istruzioniii{\setlength{\fboxsep}{1.5ex}\setlength{\fboxrule}{1.2pt}{\sffamily
\framebox{\parbox{\textwidth}{\textbf{Some other instructions.}}}}\\[3ex]}
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = pdflatex
% !TEX root = master3DM-1IQ-2021-22.tex

\newproblem{
\FPsetpar{a}{-13}{-3}


\begin{problem}\PTs{2} Dato il polinomio
$$
-2x^3 \FPsignpol{-4*\a+7}{x^2}\FPsignpol{-2*\a*\a+11*\a-4}{x}\FPsignpol{4*\a*\a-6*\a-4}{}
$$
$$
-2x^3 \FPsignpoli{-4*\a+7}{x^2}\FPsignpoli{-2*\a*\a+11*\a-4}{x}\FPsignpoli{4*\a*\a-6*\a-4}{}
$$
\begin{itemize}
\item[2.1]\PTs{1,25} Studiane il segno.
\item[2.2]\PTs{0,25} Indica per quali valori di $x$ il polinomio dato non si annulla;
\item[2.3]\PTs{0,25} Indica per quali valori di $x$ il polinomio dato è positivo;
\item[2.4]\PTs{0,25} Indica per quali valori di $x$ il polinomio dato è negativo.
\end{itemize}
\textit{Suggerimento: dividi il polinomio per $(x-2)$.}
\begin{solution}
Dopo aver diviso il polinomio dato per $(x-2)$, si ottiene che
$$
-2x^3 \FPsignpol{-4*\a+7}{x^2}\FPsignpol{-2*\a*\a+11*\a-4}{x}\FPsignpol{4*\a*\a-6*\a-4}{}
=
(x-2)(-2x^2\FPsignpol{-4*\a+3}{x}\FPsignpol{-2*\a*\a+3*\a+2}{})
$$
l'ultimo fattore di secondo grado ha, a sua volta, due radici: $\displaystyle\sempliz{-2*\a-1}{2}$ e $\FPsv{2-\a}$, pertanto il segno del polinomio dato scaturisce da quello dei due fattori trovati:
\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\draw[->] (0,0)-- (8,0) node[above,right]{$x$};
\draw (2,-3) -- (2,0) node[above]{$2$};
\draw (4,-3) -- (4,0) node[above]{$\displaystyle\sempliz{-2*\a-1}{2}$};
\draw (6,-3) -- (6,0) node[above]{$\FPsv{2-\a}$};
\draw (-0.5,-1) node[left]{$x-2$};
\draw (0,-1)--(2,-1) node[fill=white]{$0$};
\draw[dashed] (2.2,-1)--(8,-1);
\draw (-0.5,-2) node[left]{$-2x^2\FPsignpol{-4*\a+3}{x}\FPsignpol{-2*\a*\a+3*\a+2}{}$};
\draw (0,-2) -- (4,-2) node[fill=white]{$0$};
\draw[dashed] (4.2,-2)--(6,-2) node[fill=white]{$0$};
\draw (6.2,-2) -- (8,-2);
\draw (-0.5,-3) node[left]{$-2x^3 \FPsignpol{-4*\a+7}{x^2}\FPsignpol{-2*\a*\a+11*\a-4}{x}\FPsignpol{4*\a*\a-6*\a-4}{}$};
\draw (0,-3)--(2,-3) node[below]{$0$};
\draw[dashed] (2,-3)--(4,-3) node[below]{$0$};
\draw (4,-3)--(6,-3) node[below]{$0$};
\draw[dashed] (6,-3)--(8,-3);
\end{tikzpicture}
\end{center}
\end{figure}
Questo grafico conclude lo studio richiesto nel quesito 2.1. 
Pertanto, 
\begin{itemize}
\item[2.2] il polinomio non si annulla per $x\neq 2\;\wedge \;x\neq\displaystyle\sempliz{-2*\a-1}{2}\;\wedge\;x\neq \FPsv{2-\a}$;
\item[2.3] il polinomio è positivo per $x<2\;\vee\;\displaystyle\sempliz{-2*\a-1}{2}<x<\FPsv{2-\a}$;
\item[2.4] il polinomio è negativo per $2<x<\displaystyle\sempliz{-2*\a-1}{2}\;\vee\; x>\FPsv{2-\a}$.
\end{itemize}


(Il valore del parametro è $\a$)
\end{solution}
\end{problem}
}

答案1

不要使用FPsignpol\FPsignpoli,而要使用\printcoeffwhere

\usepackage{xfp}
\newcommand{\printcoeff}[1]{%
  \ifnum\inteval{#1}<0
    \inteval{#1}%
  \else
    +\inteval{#1}%
  \fi
}

区别如下:

在此处输入图片描述

\[
  -2x^3 \FPsignpol{-4*\a+7}{x^2}\FPsignpol{-2*\a*\a+11*\a-4}{x}\FPsignpol{4*\a*\a-6*\a-4}{}
\]
\[
  -2x^3 \printcoeff{-4*\a+7}x^2 \printcoeff{-2*\a*\a+11*\a-4}x \printcoeff{4*\a*\a-6*\a-4}
\]

答案2

\FPval包的宏esami并不完全等同于包\FPeval的宏FP,因为如果指定了选项,它允许打印插入表达式的参数版本param(否则它将计算结果)。因此,为了在数字和参数版本中实现所需的更好的间距,您可以使用这个略微修改的宏定义\FPsignpol

    \newcommand{\FPsignpol}[2]{\FPval\tempsign{#1}
    \ifthenelse{\equal{#2}{}}{\ifnum \tempsign<0 {\:\sempli{\tempsign}                               
    {1}#2}\else \ifnum \tempsign>0{\:+\:\sempli{\tempsign}{1}#2}\else{}
    \fi\fi}
    {\ifnum \tempsign<0 {\:\semplix{\tempsign}{1}#2\:}\else \ifnum 
    \tempsign>0{\:+\:\semplix{\tempsign}{1}#2}\else{}\fi\fi}} 

您可以在下图中看到旧版本、您的版本和新版本的宏的结果3 个宏的结果

相关内容