1
\documentclass{beamer}

\mode<presentation>
{
  \usetheme{AnnArbor}      % or try Darmstadt, Madrid, Warsaw, ...
  \usecolortheme{wolverine} % or try albatross, beaver, crane, ...
  \usefonttheme{default}  % or try serif, structurebold, ...
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
} 

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{patterns,arrows,decorations.pathreplacing,calc} 



\begin{document}



\begin{frame}{}

\begin{figure}[H]
\centering

\begin{tikzpicture}[xscale=5,yscale=5]

\draw [<->] (0,1)--(0,0)--(1,0);


\def\constal{2/3};

\def\constax{\constal}

\def\constax{(1-\constal)^2}

\def\constA{\constx/(\constx+\consty)};

\def\constB{(\constal-\constx)/(1-\constx-\consty)};

\def\constC{(1-2*\constal+\constx)/(\constx+\consty)};

\def\constD{\constal^2/(\constal^2+(1-\constal)^2)};

\def\constE{1/2};

\def\constF{(1-\constal)^2/(\constal^2+(1-\constal)^2)};

\def\constG{(\constal^2+(1-\constal)^2)/2};

\def\constH{2*\constal*(1-\constal)};

\def\constI{(\constx+\consty)/2};

\def\constJ{1-\constx-\consty};

\node [below] at (1,0) {$\beta_1$};
\node [left] at (0,1) {$\beta_4$};

\draw ({(\constD-\constC)/(\constA-\constC)},{0})--({(\constD-\constC)/(\constA-\constC)},{1});

\draw[domain=0:1] plot (\x, {-\constG/\constH*\x+(\constA*\constI-\constF*\constG)/(\constA*\constH)});

\end{tikzpicture}

\end{figure}

\end{frame}


\end{document}

I defined several constants, but they cannot work in tikz. What is the mistake?

Ypbor
  • 399
  • def is roughly speaking "text substitution", not "define constant". Try substituting the raw values inside the macros, you see it won't work either – user202729 May 15 '22 at 03:21
  • 1
    Use pgf math set macro instead: https://tex.stackexchange.com/a/235504/250119 – user202729 May 15 '22 at 03:22
  • \def is a TeX primitive, so as a rule I suggest avoiding any use of such primitives in LaTeX code. If you want to define a new LaTeX macro, use \newcommand. If you want to define a PGF constant, use \pgfmathsetmacro as @user202729 suggested above. – Miyase May 15 '22 at 10:13
  • 1
    It seems like you are not very familiar with the concept of this site, e. g. accepting answers, see https://tex.stackexchange.com/tour for a quick tour. – Dr. Manuel Kuehner May 16 '22 at 01:58

1 Answers1

1

Another option (instead of or in addition to \pgfmathsetmacro), is to use TikZ declare function. You then need some gimmick when you want to print the values (I use siunitx for this, it has a lot of formatting options).

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{siunitx}
\begin{document}
\newcommand{\print}[2][round-mode=figures, round-precision=3]{%
    \pgfmathsetmacro{\rpval}{#2}%
    \num[#1]{\rpval}
}
\tikzset{declare function={
        a=2/3;
        b(\x)=(\x)^2 +1;
    }}
\begin{tikzpicture}[]
    \draw[cyan] (0,0) grid (2,2);
    \draw ({a}, 0) -- ({b(a)}, 1); % {} are needed only in the second
                                   % coord, but better keep consinstency
    \node[below]{a=\print{a}, b=\print{b(a)}};
\end{tikzpicture}
\end{document}

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125