soulmachine / leetcode

LeetCode题解,151道题完整版。
BSD 3-Clause "New" or "Revised" License
11.3k stars 3.43k forks source link

MWE for Codex #103

Closed Ynjxsjmh closed 4 years ago

Ynjxsjmh commented 4 years ago

I tried with the following code, but it gives me the error Extra }, or forgotten $.

\documentclass[11pt]{article}

\usepackage{fancyvrb}

\input{verbatim.cls}

\DefineVerbatimEnvironment%
  {Codex}{Verbatim}
  {fontsize=\small,baselinestretch=0.9,xleftmargin=3mm,%
  frame=lines,labelposition=all,framesep=5pt}

\begin{document}

\begin{Codex}[label=bfs_template.cpp]
#include "bfs_common.h"

/**
 * @brief 广搜,只用一个队列.
 * @param[in] start 起点
 * @param[in] data 输入数据
 * @return 从起点到目标状态的一条最短路径
 */
vector<state_t> bfs(state_t &start, const vector<vector<int>> &grid) {
    queue<state_t> q; // 队列
    unordered_set<state_t> visited; // 判重
    unordered_map<state_t, state_t> father; // 树,求路径本身时才需要

    // 判断当前状态是否为所求目标
    auto state_is_target = [&](const state_t &s) { /*...*/ };

    assert (start.level == 0);
    q.push(start);

    return vector<state_t>();
    //return 0;
}
\end{Codex}

\end{document}

Is there a MWE to reproduce it?

image

Ynjxsjmh commented 4 years ago

It is the underscore symbol in label=bfs_template.cpp that causes the problem. To escape it, you could either use backslash like \_ or underscore package.

If one wants to use some special characters in label, according to fancyvrb manual , it must be put inside a group which is {}.

verbatim.cls and format.cls is from chenshuo's typeset.