我正在玩这个gamebook
包,它可以重现游戏书在 LaTeX 中。
许多这样的书在每页的底部都放有几个d6
骰子,这样读者只需随意打开书中的一页就可以模拟掷骰子,以通过冒险中遇到的挑战。
我想在我的实验中重现相同的效果:借助该fancyhdr
包,可以轻松修改页脚以包含一些通过该epsdice
包生成的骰子。
但不幸的是,该\epsdice{<value>}
命令需要一个值,该值要么是 1 到 6 之间的数字,要么是包含该值的变量,而我一点头绪都没有如何随机生成这样的值并将其传递给命令。
有人可以帮忙吗?
请参阅下面平均能量损失主要借鉴了gamebook
包中的例子。
\documentclass[10pt,twoside]{article}
\usepackage{polyglossia}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[osf]{libertine}
\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks=true,linkcolor=Emerald,urlcolor=RoyalBlue]{hyperref}
\usepackage[debug,draft]{gamebook}
\usepackage{epsdice}
\usepackage{fancyhdr}
\fancyfoot[CE,CO]{\epsdice{2}\epsdice{5}} %% MODIFY THIS
\fancyfoot[LE,RO]{\thepage}
\title{Example for using the \textsf{gamebook} package}
\author{}
\date{}
\renewcommand{\gbturntext}{turn~to~}
\renewcommand{\gbheadtext}{Gamebook Example}
\begin{document}
\maketitle
\pagenumbering{arabic}
\gbheader
\section*{Introduction}
This is an example for using the \textsf{gamebook} package that can be used for typesetting gamebooks with \LaTeX. If you do not know what a gamebook is, just have a look at the informative Wikipedia article
\begin{center}
\url{http://en.wikipedia.org/wiki/Gamebook}
\end{center}
or check out Demian's very good overview website, where you can find tons of information about gamebooks:
\begin{center}
\url{http://www.gamebooks.org}
\end{center}
The example text is a modified translation of the ``Spielbuch''-example on Wikipedia, \url{http://de.wikipedia.org/wiki/Spielbuch} used under CC-by-sa-3.0, \url{http://creativecommons.org/licenses/by-sa/3.0/legalcode}. Many thanks go to the authors of that article.
\gbsection{start}
You are locked in a strange room. Right in front of you, there is a big red button with a bright sign above it. On the northern wall, there is a heavy steel door. What would like to do in order to escape this room?
\begin{gbturnoptions}
\gbitem{Press the red button}{redbutton}
\gbitem{Read the sign above the button}{signread}
\gbitem{Try to open the steel door}{steelclosed}
\end{gbturnoptions}
\gbsection{wrongsec}
Sections like this do not exist in typical gamebooks, because you cannot access them. In this example, such a section is only included in order to show you that you are reading the text in a ``wrong'' way. After section~1, you do not read directly section~2, but you proceed with the section you chose in section~1. This kind of interaction is what makes gamebooks a lot of fun. Now, please choose an option from section~1 above.
\gbsection{redbutton}
When you press the button, the whole building explodes. The game is over, please restart and remember: save early, save often.
\gbsection{steelopen}
You enter the code and a green light starts blinking. The heavy steel door opens. If you want to leave the room, \gbturn{steelleave}, if you would rather like to press the red button, \gbturn{redbutton}.
\gbsection{steelclosed}
The door is locked, but you find a small keypad right next to it. The pad's display reads ``ENTER CODE''. Do you know the right code? If so, turn to the section with the respective number. If you do not know the code, you can either press the red button (\gbturn{redbutton}) or read the sign above it (\gbturn{signread}).
\gbsection{signread}
The sign reads:
\begin{quote}
``\emph{This is a simple little example that shows the typical structure of a gamebook. The original version was written for the German Wikipedia. And by the way, the code for the heavy steel door is `\ref{steelopen}'. Have fun and better do not press the red button!}''
\end{quote}
With this new and hopefully valuable information, you wonder what to do next. If you think the warning is just for fun and, thus, would like to press the red button, \gbturn{redbutton}. If you would like to examine the heavy steel door, \gbturn{steelclosed}.
\gbsection{steelleave}
Congratulations, you made it! Sunshine falls on your eyes and after you got used to the bright light, you see an angry \textsc{Orc} running towards you, a blood-stained knife ready in its claw. You have no choice but to defend yourself.
\gbvillain{Orc}{Skill}{5}{Stamina}{6}
The fight begins, but that is another story\dots
\end{document}
答案1
如果没有的话会稍微简单一些xelatex
,\pdfuniformdeviate
可以使用或xfp
,\fpeval
但我改用在\pgfmathparse{random(6)}
和之间生成一个整数随机数1
并将6
结果存储在中\pgfmathresult
。这可以在\epsdice
中用作\epsdice{\pgfmathresult}
。
为了简化这一点,我制作了一个小宏来执行此操作:\myrandomdice
。
由于\myrandomdice
在发货期间在页脚中调用,因此每页上的骰子都是随机的(具有相关的页面样式),当然,此处显示的第二页的输出将与本地编译不同(除非明确设置随机种子)
当然,随机数只是伪随机数。要设置种子,请使用\pgfmathsetseed{integer}
,其中整数代表任意整数。
\documentclass[10pt,twoside]{article}
\usepackage{polyglossia}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[osf]{libertine}
\usepackage[dvipsnames]{xcolor}
\usepackage[debug,draft]{gamebook}
\usepackage{epsdice}
\usepackage{pgf}
\newcommand{\myrandomdice}{%
\pgfmathparse{random(6)}\epsdice{\pgfmathresult}%
}
\usepackage[colorlinks=true,linkcolor=Emerald,urlcolor=RoyalBlue]{hyperref}
\usepackage{fancyhdr}
\fancyfoot[CE,CO]{\myrandomdice\quad\myrandomdice} %% MODIFY THIS
\fancyfoot[LE,RO]{\thepage}
\title{Example for using the \textsf{gamebook} package}
\author{}
\date{}
\renewcommand{\gbturntext}{turn~to~}
\renewcommand{\gbheadtext}{Gamebook Example}
\begin{document}
\maketitle
\pagenumbering{arabic}
\gbheader
\section*{Introduction}
This is an example for using the \textsf{gamebook} package that can be used for typesetting gamebooks with \LaTeX. If you do not know what a gamebook is, just have a look at the informative Wikipedia article
\begin{center}
\url{http://en.wikipedia.org/wiki/Gamebook}
\end{center}
or check out Demian's very good overview website, where you can find tons of information about gamebooks:
\begin{center}
\url{http://www.gamebooks.org}
\end{center}
The example text is a modified translation of the ``Spielbuch''-example on Wikipedia, \url{http://de.wikipedia.org/wiki/Spielbuch} used under CC-by-sa-3.0, \url{http://creativecommons.org/licenses/by-sa/3.0/legalcode}. Many thanks go to the authors of that article.
\gbsection{start}
You are locked in a strange room. Right in front of you, there is a big red button with a bright sign above it. On the northern wall, there is a heavy steel door. What would like to do in order to escape this room?
\begin{gbturnoptions}
\gbitem{Press the red button}{redbutton}
\gbitem{Read the sign above the button}{signread}
\gbitem{Try to open the steel door}{steelclosed}
\end{gbturnoptions}
\gbsection{wrongsec}
Sections like this do not exist in typical gamebooks, because you cannot access them. In this example, such a section is only included in order to show you that you are reading the text in a ``wrong'' way. After section~1, you do not read directly section~2, but you proceed with the section you chose in section~1. This kind of interaction is what makes gamebooks a lot of fun. Now, please choose an option from section~1 above.
\gbsection{redbutton}
When you press the button, the whole building explodes. The game is over, please restart and remember: save early, save often.
\gbsection{steelopen}
You enter the code and a green light starts blinking. The heavy steel door opens. If you want to leave the room, \gbturn{steelleave}, if you would rather like to press the red button, \gbturn{redbutton}.
\gbsection{steelclosed}
The door is locked, but you find a small keypad right next to it. The pad's display reads ``ENTER CODE''. Do you know the right code? If so, turn to the section with the respective number. If you do not know the code, you can either press the red button (\gbturn{redbutton}) or read the sign above it (\gbturn{signread}).
\gbsection{signread}
The sign reads:
\begin{quote}
``\emph{This is a simple little example that shows the typical structure of a gamebook. The original version was written for the German Wikipedia. And by the way, the code for the heavy steel door is `\ref{steelopen}'. Have fun and better do not press the red button!}''
\end{quote}
With this new and hopefully valuable information, you wonder what to do next. If you think the warning is just for fun and, thus, would like to press the red button, \gbturn{redbutton}. If you would like to examine the heavy steel door, \gbturn{steelclosed}.
\gbsection{steelleave}
Congratulations, you made it! Sunshine falls on your eyes and after you got used to the bright light, you see an angry \textsc{Orc} running towards you, a blood-stained knife ready in its claw. You have no choice but to defend yourself.
\gbvillain{Orc}{Skill}{5}{Stamina}{6}
The fight begins, but that is another story\dots
\end{document}