Can I write cls files in LaTeX instead of TeX? - latex

I have some initialization code in a XeLaTeX file which I would like to put into a separate file so that I can reuse it in future texts. What is the fastest way to convert my XeLaTeX code to a LaTeX class file?

You can put your preamble code into a .cls file and then use \documentclass{mydocstyle} to load it. Your .cls file will look like this:
% Declare that this document class file requires at least LaTeX version 2e.
\NeedsTeXFormat{LaTeX2e}
% Provide the name of your document class, the date it was last updated, and a comment about what it's used for
\ProvidesClass{mydocstyle}[2010/09/13 Bluetulip's custom LaTeX document style]
% We'll pass any document class options along to the underlying class
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{article}% or book or whatever
}
% Now we'll execute any options passed in
\ProcessOptions\relax
% Instead of defining each and every little detail required to create a new document class,
% you can base your class on an existing document class.
\LoadClass{article}% or book or whatever you class is closest to
% Now paste your code from the preamble here.
% Replace \usepackage with \RequirePackage. (The syntax for both commands is the same.)
% Finally, we'll use \endinput to indicate that LaTeX can stop reading this file. LaTeX will ignore anything after this line.
\endinput
Note that document class files can get much more complicated (if you want to include options like \documentclass[option]{mydocstyle}, etc.), but this basic format should get you started.
Save your file as mydocstyle.cls and put it in the current directory with your .tex file.
You can also take a look at the LaTeX2e for class and package writers guide. It'll walk you through this in more detail.

Related

Export tex document which uses the exam class (Part 2)

I would like to export a text document which uses the exam class to markdown. To do so, I am currently using a workaround which was suggested in this answer, which relies on pseudo-definitions which in turn overwrite the definitions of the exam class such that pandoc can produce a clean markdown file.
Although, the workaround works for the suggested multiple-choice questions, I cannot adopt the solution to work for text with “fillin gaps” such as the document below:
\documentclass[answers]{exam}
\usepackage{minted}
\let\oldpart\part
\renewcommand{\part}[1][]{\oldpart[#1]{}}
\begin{document}
\begin{questions}
\question Exercise 1
\begin{parts}
\part[1] This fills in the \fillin[blanks][3cm]
\end{parts}
\end{questions}
\end{document}
If I use the following pseudo-definitions in a separate file:
% ignore \part
\renewcommand{\part}[0][1]{}
% Treat checkboxes like an itemized list
\newenvironment{checkboxes}{\begin{itemize}}{\end{itemize}}
\renewcommand{\CorrectChoice}{\item ☒ }
\renewcommand{\choice}{\item ☐ }
\renewcommand\fillin[2][{}]{\textbf{#1}}
I get the following broken markdown output
This fills in the **blanks**3cm\]
Moreover is there a way for pandoc to ignore \begin{parts} and \end{parts} so that there are no ::: in the final Markdown file?
The \fillin problem can be solved with
\newcommand{\fillin}[1][1]{\textbf{#1}\noop}
whereas the parts div can be removed with
\newenvironment{parts}{}{}

use scholar.google.com reference in latex file

When I use scholar.google.com to get the full reference code (BibTeX) such as
#article{li2018design,
title={Design and implementation of building structure monitoring system based on radio frequency identification (RFID)},
author={Li, Hongwei and Ren, Yilei},
journal={International Journal of RF Technologies},
volume={9},
number={1-2},
pages={37--49},
year={2018},
publisher={IOS Press}
}
Then go to the journal template file, I want to copy the reference from scholar.google.com and paste it into the LaTex journal template file without doing any modification.
The template file looks like this:
Unfortunately, the paste in the template file does NOT work.
Here is the error message:
Can you assist of how to do it and make the file work correctly?
The format given by Google scholar has to be used when you compile, in order, with
Latex (or PDFLatex)
Bibtex
Latex (or PDFLatex)
Latex (or PDFLatex)
where you store the entries of your bibliography in a separate file named <mydoc>.bib.
You are simply using \thebibliography environment, which allows you to write \bibitems, which is a simpler approach (even if I suggest to use it when you have a small number of bibliography entries). If you have to use this latter approach, you have to rewrite the reference retrieved in Google scholar in the format needed by your document.
Have a look here: it explains very well the differences.

Individual function docs in LaTeX using doxygen

I'm writing a manual of sorts in LaTeX for some software. I'm constrained to use the article class. I must include docs of individual c++ classes in the manual. I'm looking at doxygen for this, but I've never used doxygen (if there's a better way, let me know).
I can get doxygen to produce a nice LaTeX (--> pdf) file of my entire project. But what I'd like to do is somehow extract the LaTeX source for each class and drop it into my LaTeX manual source at the appropriate place.
I've tried putting all the preamble stuff from refman.tex (generated by doxygen) in my preamble, and then later in the document using \input to include the tex file of an individual class. After cleaning up a few conflicts, I get to one that I don't know how to get past. The doxygen-generated doxygen.sty file makes reference to \chaptermark, but I believe that this is a macro defined in the book class.
So 1.) Am I going about this all the wrong way? 2.)Is it possible to force Doxygen to produce code in the article class? 3.) Anything else?
-garyp
You can make doxygen produce a document that uses the article document class by setting COMPACT_LATEX to YES in your doxygen config file.

How to add a (large) code appendix in LaTeX / LyX?

I'd like to add a code appendix to my LyX document. There are a few options I already considered, but they all have their problems.
I know a bit about listings, but one problem with those is that, if I copy & paste my code into them, I lose all enters/newlines. Since the code is too large to correct by hand, I was wondering if there is an alternative.
In LyX there is the possibility of inserting child documents, but that seems to be only for .tex files. Would have been ideal if I could just insert my .java file as a child document.
I could print the code to PDF, but it will include margins that mess up the final document, since the PDF is placed on the left margin of the final document and then there is the margin of the PDF. Also, this PDF always contains the entire code and white areas where not the entire page has been filled.
Does anyone have good alternative?
The listings package found here
http://www.ctan.org/tex-archive/macros/latex/contrib/listings/
allows the include of external source code files (look into the reference for \lstinputlisting).
EDIT: here you find some samples how to use it:
http://en.wikibooks.org/wiki/LaTeX/Packages/Listings
If you need to copy-paste code to LyX listing box then use Edit -> Paste Special -> Seletion or Ctrl+Alt+V.
For what it's worth, at least the 2.0 versions of LyX have the ability to include listings as child documents. Insert, File, Child Document, and choose from the dropdown box "Program Listing". This uses the listings package and lets you keep your source in its own file.
If listings doesn't support your language, you can always use something like highlight or source-highlight to generate a latex snippet of syntax-highlighted code that you can add as a child document of type "Input"
Yes, if you copy&paste code into the LyX listings box, you lose all newlines, but you can preprocess your code (insert an extra newline below each line):
$ cat foo.java | sed -e 's/$/\n/' > bar.java
Then you can copy&paste the new file bar.java and everything will be ok.

LaTeX: Cite, but don't reference

I'm producing a set of documents in LaTeX, and I would like to provide a single, global bibliography page for the whole set. This is because each document is page-limited: I don't want to take up space with references at the bottom of each one.
This means in each case, I would like to cite in the text, but not produce a reference at the end. I am using bibtex/natbib to handle the referencing.
Simplest example:
\documentclass[]{article}
\bibliographystyle{/usr/share/texmf/bibtex/bst/natbib/plainnat.bst}
\usepackage{natbib}
\begin{document}
In \citet*{MEF2010} I described the method.
\bibliography{bibliography.bib}
\end{document}
How can I do this? Essentially I just want it to cite correctly:
In Bloggs, Blagg and Blog (2010) I described the method.
But not add a references section at the end. Any ideas?
Thanks,
David
Instead of using \bibliography{bibliography.bib} you can try \nobibliography{bibliography.bib}.
You still need to enter the path so it can make the cross-references.
It happens due to missing packages. If you want to resolve the problem then enable the automatic installation packet. After that,First, you run the BibTeX file and generate the Pdf file (instead of pdfLatex file) and then pdfLatex to Pdf

Resources