追风少年
追风少年
这家伙很懒,什么也没写!

注册于 5年前

回答
5
文章
0
关注者
0

This is a MWE.

\documentclass{book}
\usepackage{lipsum}

% -------------------------------
% Counter
\newcounter{exercise}[chapter]
\renewcommand{\theexercise}{\thechapter.\arabic{exercise}}
% -------------------------------
% Exercises environment (list-based)
\newenvironment{exercises}
{%
    \par\vspace{\baselineskip}%
    \noindent\rule{\textwidth}{0.8pt}\par%
    \vspace{0.5\baselineskip}%
    \begin{list}{}{%
        \setlength{\leftmargin}{0pt}%
        \setlength{\itemindent}{0pt}%
        \setlength{\listparindent}{0pt}%
        \setlength{\labelwidth}{0pt}%
        \setlength{\labelsep}{0pt}%
        \setlength{\itemsep}{1.5\baselineskip}%
        \setlength{\parsep}{0pt}%
        \setlength{\topsep}{0pt}%
    }%
}
{%
    \end{list}%
    \vspace{0.5\baselineskip}%
    \noindent\rule{\textwidth}{0.8pt}\par%
    \vspace{\baselineskip}%
}
% -------------------------------
% List of Exercises machinery
\newcommand{\listexercisename}{List of Exercises}
\makeatletter
\newcommand{\listofexercises}{%
  \chapter*{\listexercisename}%
  \@starttoc{loe}%
}
\newcommand\l@exercise[2]{%
  \@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}}
\makeatother
% -------------------------------
% Patch \item to also add to .loe
\let\olditem\item
\renewcommand{\item}[1][]{%
  \refstepcounter{exercise}%
  \addcontentsline{loe}{exercise}{Exercise~\theexercise\ifx\relax#1\relax\else: #1\fi}%
  \olditem[\textbf{Exercise \theexercise}\quad]%
}

\begin{document}

\tableofcontents
\listoftables
\listofexercises

\chapter{Some basic mathematics}

\begin{table}
  \centering
  \begin{tabular}{c|c}
    \hline\hline
    (1,1) & (1,2) \\
    \hline
    (2,1) & (2,2) \\
    \hline\hline
  \end{tabular}
  \caption{This is a table.}\label{tbl:1}
\end{table}

\chapter{Differentiable manifolds and tensors}

\section{Definition of a manifold}

\begin{exercises}
\item \lipsum[2][1-3] $a^{2}+b^{2}=c^{2}$
\begin{equation}
  a^{2}+b^{2}=c^{2}
\end{equation}

\item \lipsum[2][1-3] $\exp(\mathrm{i}\pi)=-1$
\begin{equation}
  \exp(\mathrm{i}\pi)=-1
\end{equation}

\item \lipsum[2][1-3] $\cos^{2}\theta + \sin^{2}\theta = 1$
\begin{equation}
  \cos^{2}\theta + \sin^{2}\theta = 1
\end{equation}
\end{exercises}

\section{The sphere as a manifold}

\begin{exercises}
\item \lipsum[2][1-3] $E=\hbar \omega$
\begin{equation}
  E=\hbar \omega
\end{equation}
\end{exercises}

\end{document}

image.png

Exactly! The first requirement has been meet. The second question remains unresolved. Please see the MWE below for more details.

\documentclass{book}

% Implementation for the first requirement.
% It do work but I don't know if it is a good practice.
\newcounter{exercise}[chapter]
\renewcommand{\theexercise}{\noindent\textbf{Exercise \thechapter.\arabic{exercise}}\quad}
\newcommand{\ex}{\addtocounter{exercise}{1}\theexercise}

\begin{document}

\chapter{Some basic mathematics}

\chapter{Differentiable manifolds and tensors}

\section{Definition of a manifold}

\ex $a^{2}+b^{2}=c^{2}$

\ex $\exp(\mathrm{i}\pi)=-1$

\section{The sphere as a manifold}

\ex $\cos^{2}\theta + \sin^{2}\theta = 1$

\ex $E=\hbar \omega$

\end{document} 

受到 @u70550 的启发,最后做出来满意的结果。目前的方案如下。

\documentclass{ctexart}
\usepackage[margin=3cm]{geometry}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[colorlinks=true]{hyperref}

\definecolor{codegreen}{rgb}{0,0.5,0}
\definecolor{codeblue}{rgb}{0,0,0.8}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}

% Set listing style
\lstdefinestyle{mystyle}{
    backgroundcolor=\color{white!95!black},
    commentstyle=\color{codegreen},
    keywordstyle=\color{codeblue},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,
    captionpos=t,
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    frame=single,
    belowcaptionskip=10pt
}
\lstset{style=mystyle}

\begin{filecontents*}[overwrite]{PackedFileDemo.c}
/*    This is the main file for the Packed File Demo program
which writes an Igor Pro 3.x packed experiment file.

See Igor Pro Tech Note PTN#003 for details.
*/

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stddef.h>                    // For offsetof macro.

#include "PackedFile.h"
#include "Variables.h"
#include "IgorBin.h"
#include "CrossPlatformFileIO.h"
#include "IgorSupport.h"

#include "PackedFileDemo.h"

static int
GetNextCommand(char* filePath)
{
    char input[1024];
    int command;
    int i;
    
    *filePath = 0;
    
    while(1) {
        printf("Command: ");
        if (fgets(input, sizeof(input)-1, stdin) != NULL) {
            char* p = strchr(input, '\n');            // Find new line character.
            if (p != NULL)
            *p = 0;                                // Remove new line character.
            for(i=0; i<5; i++)
            input[i] = toupper(input[i]);        // Convert command to upper case.
            if (strncmp(input, "READ ", 5) == 0) {
                command = 1;
                strcpy(filePath, input+5);
                break;
            }
            if (strncmp(input, "WRITE ", 6) == 0) {
                command = 2;
                strcpy(filePath, input+6);
                break;
            }
            if (strncmp(input, "QUIT", 4) == 0) {
                command = 3;
                break;
            }
        }
        printf("\n\n");
    }
    
    return command;
}

int
main(void)
{
    int command;
    char filePath[1024];
    char fullPathSample[32];
    char partialPathSample[32];
    int err;
    
    #ifdef WIN32
    strcpy(fullPathSample, "C:\\FolderA\\Test Packed File.pxp");
    strcpy(partialPathSample, ".\\Test Packed File.pxp");
    #else
    strcpy(fullPathSample, "hd:FolderA:Test Packed File");
    strcpy(partialPathSample, ":SamplesMac:Test Packed File");
    #endif
    
    printf("This program illustrates reading and writing Igor packed experiment files.\n\n");
    printf("To read a file, enter the following: Read <file path>\n\n");
    printf("To write a file, enter the following: Write <file path>\n\n");
    printf("<file path> can be either a full path (%s)\n", fullPathSample);
    printf("or a partial path relative to the folder containing this program (%s)\n", partialPathSample);
    printf("\n");
    printf("Here are some sample commands:\n");
    #ifdef WIN32
    printf("  Read Test Packed File.pxp\n");
    printf("  Read .\\Test Packed File.pxp\n");
    printf("  Write Test Packed File.pxp\n");
    #else
    printf("  Read Test Packed File\n");
    printf("  Read :Test Packed File\n");
    printf("  Write Test Packed File\n");
    #endif
    
    #ifdef WIN32
    printf("To quit the program, type Quit\n");
    #else
    printf("To quit the program, choose Quit from the file menu.\n");
    #endif
    
    while(1) {
        printf("\n");
        command = GetNextCommand(filePath);
        if (command == 1)
        err = ReadPackedFile(filePath);
        if (command == 2)
        err = WritePackedFile(filePath);
        if (command == 3) {
            #ifndef WIN32
            printf("Now you must choose Quit from the File menu to quit.\n");
            #endif
            break;
        }
    }
    
    return 0;    
}
\end{filecontents*}
\begin{document}
    \begin{center}
        静夜思\\[0.5em]
        〔唐代〕李白\\[0.5em]
        床前明月光,疑是地上霜。\\
        举头望明月,低头思故乡。\\
    \end{center}
    
    我想在此处引用代码 \ref{lst:maincode}。
    
    \lstinputlisting[language=C,caption={这是一段示例代码},label={lst:maincode}]{PackedFileDemo.c}
    
    我想唱歌。
    
    \begin{center}
        凉州词二首·其一\\[0.5em]
        〔唐代〕王之涣\\[0.5em]
        黄河远上白云间,一片孤城万仞山。\\
        羌笛何须怨杨柳,春风不度玉门关。\\
    \end{center}
\end{document}

\newcommand*{\ListOfFiles}
{
bco0.dat,
fco1.dat,
hcpm0.dat
}

\foreach \i in \ListOfFiles
{
    \lstinputlisting{./src/bmdl/\i}
}

发布
问题