小编Sea*_*red的帖子

在bash脚本中使用sed替换LaTeX别名

我对bash脚本编程比较陌生,对LaTeX没有经验.我被要求开发一个脚本,用于替换LaTeX文档中的便捷快捷方式和更加繁琐的长形等价物.

到目前为止,我的方法是在单独的变量中分离快捷方式和长形式,然后尝试使用sed在文本中替换它们.我在下面附上了简短的示例文件.

因为它当前是脚本需要2个参数,一个文件expr,它从中检索快捷方式和长形式术语,以及一个应该进行适当更改的infile.我知道脚本正确地隔离了快捷方式和长格式并且可以返回它们,但它似乎无法执行sed命令.

我尝试在线搜索并发现多个类似的问题,其中建议是sed难以识别变量,并且各种类型的报价组合可能解决问题.我尝试了许多排列,但似乎都没有.在许多情况下,长形式术语包含特殊字符,如'$'和'{}',所以我怀疑这可能是问题,但我不确定.我也非常愿意接受有关如何解决问题的其他想法.请在下面找到脚本和2个参数文件expr和infile的示例.

包含快捷方式和长格式的expr文件

% a
\newcommand{\ao}{$^{18}$O}
\newcommand{\aodso}{$^{18}$O/$^{16}$O}
% b
\newcommand{\bea}{\begin{equation}}
\newcommand{\beaa}{\begin{eqnarray}}
% c
\newcommand{\cthree}{C$_3$}
\newcommand{\cfour}{C$_4$}
\newcommand{\coz}{CO$_2$}
Run Code Online (Sandbox Code Playgroud)

infile包含由long-forms替换的快捷方式

This is my test {\ao} 
{\aodso} my test is this
Does it work {\bea}
{\beaa} test test test
work work work {\cthree}
{\cfour} This is my test
my test is this {\coz}
Run Code Online (Sandbox Code Playgroud)

脚本的相关子部分用expr和infile作为参数调用

while read line; do
    if [[ $line == \newcommand* ]]; then
    temp=${line#*\{}
    sc=${temp%%\}*} 
    templf=${temp#*\{}
    lf=${templf%\}}
    #echo $sc, $lf
    sed -i -e 's/${sc}/${lf}/g' ${infile}
    fi
done < ${expr}
Run Code Online (Sandbox Code Playgroud)

更新:为了澄清,这就是期望的结果,infile中存在的快捷方式将替换为适当的长形式 …

bash latex sed variable-substitution

4
推荐指数
1
解决办法
830
查看次数

使用Org-Babel控制缩进

当用Org-Babel编写有文化的Python时,我需要能够控制缩进级别(显式地:indentation-level 3或隐式地使用一些聪明的指示).

这是一个演示此问题的示例文件.

#+BEGIN_SRC python :tangle "sample.py"
  class Test:
      def __init__(self):
          self.a = 'a test class'
#+END_SRC
#+BEGIN_SRC python :tangle "sample.py"
      def say_hi(self):
          print 'Hi from this Test object!'
          print 'ID: {}'.format(repr(self))
          print 'Data: {}'.format(str(self.__dict__))
#+END_SRC
Run Code Online (Sandbox Code Playgroud)

python emacs literate-programming org-mode org-babel

4
推荐指数
1
解决办法
1411
查看次数

在 Gatsby 构建期间检索文件内容

我需要提取程序源文件的内容,以便在 Gatsby 生成的页面中显示。我已经把所有东西都连接到了我应该可以打电话的地方

// my-fancy-template.tsx
import { readFileSync } from "fs";
// ...
const fileContents = readFileSync("./my/relative/file/path.cs");
Run Code Online (Sandbox Code Playgroud)

但是,在运行gatsby develop或 时gatsby build,出现以下错误

未找到此依赖项: ? * fs 在 ./src/templates/my-fancy-template.tsx 中?要安装它,您可以运行: npm install --save fs

但是,所有文档都表明该模块是 Node 原生的,除非它在浏览器上运行。我还不太熟悉 Node,但考虑到它gatsby build也失败了(这个命令甚至没有启动本地服务器),如果这是问题所在,我会有点惊讶。

我什至从一个新的测试站点 ( gatsby new test) 尝试了同样的效果。

node.js gatsby

4
推荐指数
1
解决办法
877
查看次数

WPF类加载错误?添加自定义类时崩溃

弹出

An unhandled exception of type 'System.IO.IOException' occurred in
PresentationFramework.dll

Additional information: Cannot locate resource 'mainwindow.xaml'.
Run Code Online (Sandbox Code Playgroud)

输出日志

'markless.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
...
'markless.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll'
The thread 'vshost.NotifyLoad' (0x6b0) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x1fa8) has exited with code 0 (0x0).
'markless.vshost.exe' (Managed (v4.0.30319)): Loaded 'T:\#_\Programming\GitHub\markless\src\win2\markless\bin\Debug\markless.exe', Symbols loaded.
Step into: Stepping over method without symbols 'markless.App.App'
'markless.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
A first chance exception of type 'System.IO.IOException' occurred in PresentationFramework.dll
An unhandled …
Run Code Online (Sandbox Code Playgroud)

wpf runtime-error class

3
推荐指数
1
解决办法
2661
查看次数

NLTK 正则表达式和 CFG

以 NLTK 的文档为例的“正则表达式”和同一个 CFG 之间在功率上有什么实际区别吗?肯定应该有,因为有不规则的上下文无关语言,但我找不到一个具体的例子,其中 CFG 方法胜过正则表达式。

http://nltk.org/book/ch07.html

python regex nlp nltk context-free-grammar

3
推荐指数
1
解决办法
1301
查看次数

(原始对象)中有哪些不同的部分?

(pr +)
;=> #object[clojure.core$_PLUS_ 0x4e648e99 "clojure.core$_PLUS_@4e648e99"]
Run Code Online (Sandbox Code Playgroud)

对于更复杂的示例,这似乎是一致的模式:

#object[namespace$symbol addr "namespace$symbol@addr"]
Run Code Online (Sandbox Code Playgroud)

这里第三个元素的目的是什么?什么时候不遵循这种模式?

debugging clojure

3
推荐指数
1
解决办法
67
查看次数

如何将当前git提交插入组织模式缓冲区以在导出时进行评估?

#+Author: A. U. Thor
#+Date: [2014-01-06 Mon]
#+MACRO: version 2.1

#+BEGIN_SRC emacs-lisp :exports none :tangle no
  (substring (shell-command-to-string "git rev-parse --short HEAD") 0 -1)
#+END_SRC

This document interacts with version {{{version}}} of the
StackExchange API and is maintained by {{{author}}}.  It was last
modified at {{{modification-time(%Y-%m-%dT%T%z)}}} (commit ??).  This
copy was exported on {{{time(%Y-%m-%dT%T%z)}}}.
Run Code Online (Sandbox Code Playgroud)

产生

                              ____________

                                  TEST

                               A. U. Thor
                              ____________


                            [2014-01-06 Mon]


Table of Contents
_________________




This document interacts with version 2.1 of the StackExchange API and is
maintained …
Run Code Online (Sandbox Code Playgroud)

git elisp export org-mode

2
推荐指数
1
解决办法
206
查看次数

为什么我必须在将二维数组传递给C函数时提供维度?

我不确定标签是否相关,但可以随意添加它.我认为原因是历史性的,这就是我建议的原因.

为什么我不能声明如下的函数签名?

void foo(int doubly_indexed_array[][]) {
  ...
}
Run Code Online (Sandbox Code Playgroud)

这使

$ gcc mem.c
mem.c:4: error: array type has incomplete element type
Run Code Online (Sandbox Code Playgroud)

为什么必须声明其中一个尺寸,如下所示?

void foo(int doubly_indexed_array[][10]) {
  ...
}
Run Code Online (Sandbox Code Playgroud)

c memory-management multidimensional-array

2
推荐指数
1
解决办法
241
查看次数

我怎样才能简化这个 Makefile 以减少重复?

Make 是我在是否理解它之间来回切换的技术之一。

这当然是我知道我一定做错了什么的一个例子,因为 Make 的开发是为了减少这些任务的重复性。

all: 24.1 24.2 24.3

24.1:
    evm install emacs-24.1-bin || true
    emacs --version
    emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit
24.2:
    evm install emacs-24.2-bin || true
    emacs --version
    emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit
24.3:
    evm install emacs-24.3-bin || true
    emacs --version
    emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit
Run Code Online (Sandbox Code Playgroud)

如何编辑此 Makefile 以仅布置一次测试序列但能够针对多个版本进行测试?

makefile

2
推荐指数
1
解决办法
230
查看次数

有效地获取借用引用的所有权以从函数返回

我正在尝试编写一个简单的prompt函数,它返回一个输入字符串而不带尾随换行符,但我无法返回我的结果,因为它的input寿命不够长。我知道这String::trim_right_matches是返回对 的一部分的借用引用input: String,但我不知道如何获得该数据的所有权或以某种方式复制它以返回它。

我已经转了几个小时了,但没有运气,尽管我知道这种“与借用检查器的斗争”是 Rust 新手的必经之路,所以我想我并不孤单。

use std::io;
use std::io::Write;

fn main() {
    println!("you entered: {}", prompt("enter some text: "));
}

fn prompt(msg: &str) -> &str {
    print!("{}", msg);

    io::stdout().flush()
        .ok()
        .expect("could not flush stdout");

    let mut input = String::new();

    io::stdin()
        .read_line(&mut input)
        .expect("failed to read from stdin");

    input.trim_right_matches(|c| c == '\r' || c == '\n')
}
Run Code Online (Sandbox Code Playgroud)

直觉告诉我我需要fn prompt(prompt: &str) -> str代替-> &str,但我无法以编译器接受的方式实现这一点。

error: `input` does not live …
Run Code Online (Sandbox Code Playgroud)

return lifetime rust

2
推荐指数
1
解决办法
6199
查看次数

def'd类型的类常量

在Python中,有没有声明要声明的类型的类成员?

class Foo:
    def __init__(self, a, b):
        self.one = a
        self.two = b

    ZERO = Foo(0, 0)
    ONE = Foo(0, 1)
Run Code Online (Sandbox Code Playgroud)

这个问题似乎是由以下事实出现的类Foo没有完全在评估的时间def'd Foo.ZEROFoo.ONE-有什么办法来克服这一点的同时保持的形式Foo.MEMBER

python singleton class

1
推荐指数
1
解决办法
100
查看次数

在.emacs中设置default-directory

我真的不知道该说些什么.

我一直在努力定制我的emacs,我注意到它实际上并没有.emacs在启动时加载我.根据(http://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html#Find-Init),emacs首先在HOME目录(~/)中查找初始化文件...

当我启动emacs时,我的.emacs文件似乎被正确读取 - .notes例如,当我访问文件时,会对钩子进行评估等等.让我感到惊讶的是:默认目录未设置 - 同一个加载文件中的命令.我可以手动评估它或只是执行(load "~/.emacs")它,它将工作正常.

我想这个问题可以概括一下:如果在load手动执行时命令按预期工作,为什么它不能自动启动?

完整(注释掉函数除外).emacs文件:

; http://stackoverflow.com/a/13946304/1443496
(defvar auto-minor-mode-alist ()
  "Alist of filename patterns vs correpsonding minor mode functions,
   see `auto-mode-alist'. All elements of this alist are checked,
   meaning you can enable multiple minor modes for the same regexp.")

(defun enable-minor-mode-based-on-extension ()
  "check file name against auto-minor-mode-alist to enable minor modes
the checking happens for all pairs in auto-minor-mode-alist"
  (when …
Run Code Online (Sandbox Code Playgroud)

emacs elisp dot-emacs

1
推荐指数
1
解决办法
566
查看次数

解释正则表达式/ ^ [a-zA-Z]*/

我知道正则表达式模式必须匹配一个字符串,该字符串以组合开头并重复以下字符:

  1. a-z
  2. A-Z
  3. a white-space character

字符串的结束没有限制!


第一个案例

所以一个字符串如uoiui897868(任何只以空格开头的字符串a-z或者A-Z)匹配模式......(当然可以)

第二个案例

但问题是一个字符串76868678jugghjiuh(任何字符串只以空格以外的字符开头,a-z或者A-Z)匹配!这不应该发生!


我也检查过使用php函数preg_match(),返回true(即模式匹配字符串).还使用过其他在线工具,如regex101regexr.com.字符串与模式匹配.任何人都可以帮助我理解为什么模式匹配第二种情况中描述的字符串?

php regex string

0
推荐指数
2
解决办法
2万
查看次数