隐形打印解决方案

隐形打印解决方案

\phantom我尝试使用以下代码在论坛上找到的一些项目:

\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}}
...
\invisiblesection{Blah}

当我尝试以不可见的方式打印以下内容时,编译都无法成功,这意味着在输入解决方案的地方留下空白。

\phantom{
For this experiment the sample space is simple to think about and write down. We can use canonical ordering to find the sample space as seen in Table \ref{tab:samplespaceexample} which yields a sample space of 

\begin{displaymath}
\Omega = \{\textrm{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}\}.
\end{displaymath}

  \begin{center}
  \begin{tabular} {ccc}
    First Toss & Second Toss & Third Toss \\\hline
    H & H & H\\
    H & H & T\\
    H & T & H\\ 
    H & T & T\\
    T & H & H\\
    T & H & T\\
    T & T & H\\
    T & T & T\\
  \end{tabular}
  \caption{Canonical ordering used to specify a sample space.}
  \label{tab:samplespaceexample}
  \end{center}
It should be noted that the sample space can be represented differently for the same random experiment if the point of interest changes. If we were interested in the number of heads instead of the specific outcomes the sample space would be

\begin{displaymath}
\Omega = \{0, 1, 2, 3\}.
\end{displaymath}
}
\end{exmp}

我应该注意,如果我仅在函数之前顶部的文本上使用幻影,\begin{displaymath}它似乎可以工作,但是一旦我进入另一个环境,它就不起作用。

答案1

我不清楚您是否想在将 PDF 打印到纸上时隐藏某些文本,或者是否想创建两个版本的 PDF(例如,一个用于内部,一个用于公开分发)。我猜是后者,Charles Henrique Porto Ferreir 的回答很棒。

如果你希望文本在 PDF 中显示,但在打印时不显示在纸上,则可以使用ocgx2 软件包

以下是一个小例子:

\documentclass{article}
\usepackage{ocgx2}

\begin{document}
\Huge Hello world!

\begin{ocg}[printocg=ifvisible]{myworldlayer}{id1}{1} 
% possible options are printocg=ifvisible or always or never
\Huge The world is a book and if you do not travel you read only one page
\end{ocg}
\end{document}

您可以选择在 Acrobat Reader 中显示或隐藏文本,并且只有当文本出现在 PDF 中时,它才会出现在纸上。要切换文本,请使用此屏幕截图中的复选框:

ocgx2_示例

打印预览:

在此处输入图片描述

答案2

我想建议一种不同的方法。您应该创建一个 if/else 案例来打印或不打印您想要的文本。这是一个简单的例子。我创建了一个名为 \showSolution 的函数。使用此功能,您可以显示或隐藏解决方案,只需注释掉 \showSolution 行,解决方案就会被隐藏

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[top=2cm,bottom=2cm,left=1cm,right=1cm]{geometry}
\usepackage[table]{xcolor}



% ---------- commands  -- -----------------------------

\newif\ifPrintSolution

\newcommand{\showSolution}{
\PrintSolutiontrue
}

\newcommand{\solution}[1]{
  \ifPrintSolution {\color{black!65}\it Solution:\\[1ex] #1} \fi
}

% ------------------------------------------------------------



\begin{document}


\showSolution

Question: This is a question...

\solution{
    This is the solution
}


\end{document}

答案3

您是否尝试过简单地将文本设为白色?使用包xcolor\textcolor{color}{text}

相关内容