我试图摆脱org导出的latex文件头中的一些包。 This教程建议将以下内容添加到emacs
:
(add-to-list 'org-export-latex-classes
'("org-article"
"\\documentclass{org-article}
[NO-DEFAULT-PACKAGES]
[PACKAGES]
[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
然而,当我开始emacs
时,我收到错误:
Symbol's value as variable is void: org-export-latex-classes
我还尝试将以下内容放入.org file
:
#+begin_src emacs-lisp :results silent
(add-to-list 'org-export-latex-classes
'("per-file-class"
"\\documentclass{scrartcl}
[NO-DEFAULT-PACKAGES]
[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
#+end_src
#+LaTeX_CLASS: per-file-class
但是,当我导出时,org-mode
会抱怨没有名为per-file-class
的类。
我如何解决这个难题? (请注意,我没有lisp
背景)
答案 0 :(得分:1)
你需要在加载ox-latex.el之后放入(add-to-list'org-export-latex-classes ....)(这是变量所在的位置)一种方法是使用eval-after-load:
namespace Foo {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
public class Program
{
public static void Main()
{
var parent = new Parent {
Children = new List<Child> {
new Child(),
new Child(),
new Child()
}
};
{
// works
var expr = BuildLambda<Parent, IEnumerable<Child>>("Children");
expr.Compile().Invoke(parent).ToList().ForEach(x => Console.WriteLine(x));
}
// works too
{
var expr2 = BuildLambda<Parent, IEnumerable<object>>("Children");
expr2.Compile().Invoke(parent).ToList().ForEach(x => Console.WriteLine(x));
}
// and this works too
ValidateEntity(parent);
}
public static void ValidateEntity<TEntity>(TEntity e)
where TEntity : class, new()
{
var propertyName = "Children";
var propType = typeof(TEntity).GetProperty(propertyName);
var expr = typeof(Program)
.GetMethod("BuildLambda", BindingFlags.Public | BindingFlags.Static)
.MakeGenericMethod(new[] { typeof(TEntity), propType.PropertyType })
.Invoke(null, new[] {propertyName});
// Here we invoke artificial method and inject property type there
typeof(Program).GetMethod("ProcessExpr")
.MakeGenericMethod(new[] { typeof(TEntity), propType.PropertyType })
.Invoke(null, new [] { expr, e });
}
public static void ProcessExpr<TEntity, TValue>(Expression<Func<TEntity, TValue>> expr, TEntity parent) {
// here we know both types
Console.WriteLine("Yay works too!");
((IEnumerable<Child>)expr.Compile().Invoke(parent)).Cast<Child>().ToList().ForEach(x => Console.WriteLine(x));
}
public static Expression<Func<TEntity, TValue>> BuildLambda<TEntity, TValue>(string property) where TEntity : class
{
var param = Expression.Parameter(typeof (TEntity), "e");
var prop = Expression.PropertyOrField(param, property);
return Expression.Lambda<Func<TEntity, TValue>>(prop, param);
}
}
public class Parent {
public List<Child> Children { get; set; }
}
public class Child { }
}
对于per-file类,您需要再次加载ox-latex,然后需要使用C-c C-c评估代码块。之后使用C-h v检查org-export-latex-classes的值,以确保它被“采用”。