0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Overleafで、ファイルを跨いだlabelの引用方法について

Posted at

論文のリプライを書いていると

よくmain.tex中の数式番号や章番号などを参照したいのに、reply.texでは参照できなくて、泣く泣く毎回数式番号などを書き換える、みたいなことがありました。

そこで、今回はOverleafでも、こういったファイル跨ぎのlabel参照の方法が分かったので、ここにまとめておきます。

ディレクトリ構造

home/
 ├ main.tex (実際の論文本文)
 ├ reply.tex (リプライ用のファイル)
 └ latexmkrc (設定ファイル)

このlatexmkrcがミソです。

latexmkrcの編集

$latex = 'platex';
$bibtex = 'pbibtex';
$dvipdf = 'dvipdfmx %O -o %D %S';
$makeindex = 'mendex %O -o %D %S';
$pdf_mode = 3; 
$ENV{TZ} = 'Asia/Tokyo';
$ENV{OPENTYPEFONTS} = '/usr/share/fonts//:';
$ENV{TTFONTS} = '/usr/share/fonts//:';

$sub_doc_output = 'output-subdoc';

@sub_doc_options = ();

push @sub_doc_options, '-pdf'; # Use pdflatex for compilation of external documents.
# Replace '-pdf' by '-pdfdvi', 'pdfxe', or 'pdflua' if needed.

push @file_not_found, '^No file\\s*(.+)\s*$';

add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );
sub makeexternaldocument {
   if ( $root_filename ne $_[0] )  {
       my ($base_name, $path) = fileparse( $_[0] );
       pushd $path;
       my $return = system "latexmk",
                           @sub_doc_options,
                           "-aux-directory=$sub_doc_output",
                           "-output-directory=$sub_doc_output",
                           $base_name;
       if ( ($sub_doc_output ne ' ') && ($sub_doc_output ne '.') ) {

            rdb_add_generated( "$sub_doc_output/$base_name.aux" );
            copy "$sub_doc_output/$base_name.aux", ".";
       }
       popd;
       return $return;
  }
}

reply.texの設定

プリアンブルにxrパッケージと、以下の設定を行ってください。

\usepackage{xr}
\externaldocument{main}

最後

これだけです!!詳しい内容などは今後補足的に追加していこうと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?