29
$\begingroup$

I have been using Mathematica for many years, mostly for plotting, derivations and numerical computations. Many times I tried to incorporate some text and formulas in my worksheets. Text is Ok, but when it comes to the formulas it becomes a disaster. This is despite that MA targets exactly this niche. Therefore, after wasting a day in searching for a solution I fall back to my usual routine, namely, typing in parallel a document in xelatex. It is not ideal, as I have to always maintain two documents, often with additional figures, inconsistent notations. The worst is that my MA worksheets cannot be self-explanatory.

Today I attempted again to figure out how to incorporate mathematical equations in the MA worksheet. I am using DisplayFormulaNumbered cells. I notice

  1. Summation indices are not in the displayed form,
  2. Some variables are in upright form, some---in italic form,
  3. Font is too small.

enter image description here

enter image description here

Already in this two examples I count many inconsistencies. $U$ is slanted in the first equation and upright in the second one. $j$ subscript is upright, however, it becomes slanted as the sub-subscript. $v$ is slanted and $U$ is upright in the same equation. This looks completely random to me. I prefer they look as

$$\large H=h \sum_\sigma\sum_{<i,j>} d_{i\sigma}^\dagger d_{j\sigma}+U\sum_{i}n_{i\uparrow} n_{i\downarrow},\\ \large v_{i\sigma_i j\sigma_j k\sigma_k l\sigma_l}=U\delta_{ij}\delta_{kl}\delta_{jk} \delta_{\sigma_{i}\sigma_{l}}\delta_{\sigma_{j}\sigma_{k}}. $$

Therefore my question:

How do you deal with such issues?

I am aware of this post. It has been closed as a duplicate of an earlier post. To my opinion, they address completely different issues: format of the equation vs. format of the equation number and do not resolve them in a satisfactory way. I have read the answer of kglr maybe ten times and still cannot figure out how to, e.g., set italic font for variables and subscripts or get rid of all inline expressions in favor of displayed ones or increase the font size.

In answering this question, please, try to provide a pedagogical answer. Go slowly, step-by-step. I do not need complicated solutions, it is not for writing a book or an article. I just need to write a short and readable technical note. I am planing to open a bonus for this question and assign a generous award for a simple and easy to use solution.

This post seems to be relevant too, but I cannot figure out which combination of options gives good looking.

$\endgroup$
8
  • $\begingroup$ I can get the summations you prefer for "H" by editing the "DisplayFormula" stylesheet and changing the font to Times Roman and size to 24 and then using and selecting the symbols for sum and sub/super scripts from the palettes. The dagger however is <esc>dg<esc>. $\endgroup$
    – josh
    Dec 30, 2021 at 13:12
  • 3
    $\begingroup$ "it is technically simpler for me to type directly in Latex". May be I was not clear or not interpreting what you said correctly. But this is what I also do. I write the Latex directly, but do it from inside the notebook. Write the Latex to file. Use TeXForm to generate the Latex for the math, and for everything else (plain text, tables, etc...) I write Latex. But it is written from inside the notebook to the latex file. As a string. But this has no effect on the Latex writing. This way you have just one source to maintain and not two. $\endgroup$
    – Nasser
    Dec 30, 2021 at 14:56
  • 2
    $\begingroup$ I share your frustration with MMA typesetting (and Presentations). One solution might be to contact WRI for a special Stylesheet, which they use for their book publications. This Stylesheet is under NDA. $\endgroup$ Dec 30, 2021 at 15:01
  • 1
    $\begingroup$ @RomkeBontekoe Wolfram used to have publicon for technical publication. But it is gone long time ago, now it routes one to solutions/industry/electronic-publishing Original publicon announcement is here technical-publishing-made-easy-with-new-wolfram-publicon-software 2004 $\endgroup$
    – Nasser
    Dec 30, 2021 at 15:15
  • 1
    $\begingroup$ For display equations, you could use MaTeX and then hide the code. $\endgroup$
    – Chris K
    Jan 1 at 0:53

2 Answers 2

6
$\begingroup$

For many years I use Mma for writing the texts that I used to call "Formulars." The formulars are the scientific reports to myself and my co-authors containing text, formulas, graphics, and their mathematical derivations in the form of the Mma code. The code I, however, hide such that it can be visualized if needed. These are not intended to be sent to any scientific journals for publications. They are rather for internal use for myself and my co-author. I use them to keep all my calculations together with the explanations not to lose them, not to forget some details with time, and to have them ready when it will come to writing a journal publication.

When it comes to sending a paper to a journal I write a tex file.

Below please find fragments of one of such a documents:

enter image description here

To make it visible, I had to decrease the multiplication factor of this document with respect to what I am really using. However, I hope it is visible enough, and you can imagine what I have on the screen. This is the beginning of the document containing the formular of my current research.

Below you can see the fragment of a text with formulas related to one of the equations. It contains some code in which I derive this equation. The latter is, however, collapsed around the cell containing the formula

enter image description here

and below you see the same fragment, but with the open code:

enter image description here

In the next image, I show the interactive demonstration I used to show the existence of the solution of some transcendental equations. The corresponding code is hidden.

enter image description here

and here you can see it with the open cell containing the code:

enter image description here

This is a 3D image obtained in the course of the solution. The code is collapsed.

enter image description here

And here I open the cell containing the code of this surface:

enter image description here

Below I typed a pair of the formulas from your question:

enter image description here

If this quality satisfies you here is the trick: I use the StyleSheet JournalArticle. All that you see in my answer has been done within this StyleSheet.

Sometimes I slightly modify this StyleSheet. For example, usually, I like to use this StyleSheet but increase the FontSize to 14 and the LineSpacing to 1.5. Like this, it is better readable. Such a modification requires minimum actions. Several times I made my own StyleSheet for my formulars. It is also possible, but now I refused such a practice, since the modified StyleSheet that I made typically produces the pdf version that does not look exactly like the nb original. Maybe you will overcome such a limitation or it does not play an important role for you. In this case, creating a custom StyleSheet offers much broader possibilities.

Edit

Below one can see a fragment of an image with the caption:

enter image description here

The image is obtained as a copy-paste from some external source, pasted into an Input cell. The cell, further, was transformed into a Figure format. Like this, the image is always centered. Then the cell was tagged. The same can be done, of course, if you make a plot for the illustration.

The next cell was created as a FigureCaption one, then the caption text was written. During writing this text, the number of the figure was entered using Menu/Insert/AutomaticNumbering/CellTag. Like this, if you later will cut the figure and the caption out and paste it into another place the numeration of the figure captions will be automatically rearranged.

I often programmatically make tables but never used TableTitle, Table, TableNote.

I also often make references and arrange them with AutomaticNumbering such that they are automatically renumbered during cutting-and-pasting. Below you see such a reference:

enter image description here

To do this I make the following trick. I create a cell with the EndNote style, type the reference there and introduce a tag. In this notebook Menu/Cell/CellTags/ShowCellTags is selected. Hence, one can see the cell tag at the left, above the reference. In this case, it is "refMuskh". Then I put the cursor in front of the reference and by using the Menu/Insert/AutomaticNumbering introduce the number of this reference. In this case, it is 1. Now one can also introduce the same way (or by copy-pasting) where needed in the text:

enter image description here

Sometimes I also make interactive elements, such as buttons that open some documents with necessary material. But these I only rarely use (mostly for lectures, rather than for formulars). I will willingly write about them if you need such elements, but then I need to look up my archives.

I will be happy to answer further questions if any.

Have fun!

$\endgroup$
6
  • $\begingroup$ Very nice! I used to work with the Default StyleSheet, therefore other possibilities are like a revelation for me. I find the JournalArticle StyleSheet has a lot of Styles, they match in many cases my expectations about the design. However, I have never seen how other styles from JournalArticle work, like TableTitle, Table, TableNote, Axiom, Figure and FigureCaption. Since you are showing figures, I would like to know if you have tried to use captions? What styles from JournalArticle do you typically use? Have you tried more complicated numbering of equations, like (1.12), or (1.a)? $\endgroup$
    – yarchik
    Jan 2 at 23:06
  • $\begingroup$ @yarchik Please see the edit to the answer. $\endgroup$ Jan 3 at 12:56
  • 2
    $\begingroup$ @yarchik As the styles, I massively use nine first styles from Menu/Format/Style, Starting from Title and down to Text. Besides, I use Figure, FigureCaption, Abstract, and EndNote. Very often I use the InlineFormula. Sometimes but rarely, I also use such styles as Item1, Item2, and so on. $\endgroup$ Jan 3 at 13:08
  • 1
    $\begingroup$ @yarchik I never used the numbering like (1.a). I tried to use something like (1.12) when I tried using the StyleSheets for books. I mean that I wanted to have a number of a chapter, and then a number of an equation within this chapter. Say, (1.12) means equation 12 of chapter 1. Here, however, I had a negative experience. Such reference styles did not work properly for me. $\endgroup$ Jan 3 at 13:28
  • $\begingroup$ Thank you, your feedback is very useful, also your negative experience with the book format. $\endgroup$
    – yarchik
    Jan 3 at 16:27
10
$\begingroup$

I found many posts here that address different aspects of my question. Some of them go far beyond my needs and understanding. They convince me that even complicated documents can be nicely typeset in MA. Most of all I was inspired by the post of Mike Honeychurch with several nice examples.

Other posts from where learned include

  1. Writing aligned equations in the TraditionalForm,
  2. A tech note on working with stylesheets,
  3. Evaluation of a cell and having the output in a numbered equation,
  4. Customizing inline equations with InlineCell style.

Before providing the actual answer, I would like to emphasize that Mathematica's default styles are far from optimal. For instance, DisplayFormulaNumbered is not typeset in the traditional form and uses serif-less fonts. The unsatisfactory example is presented in the question. Already correcting these two issues brings a huge improvement. Therefore:

  1. Open a new notebook, create a title cell as well as a section with some text. With default styles I am getting

enter image description here

  1. We are not happy with the colors, fonts, lack of section numbers. Therefore in the menu Format select Edit Stylesheet... Using normal controls customize the appearance of the title, (sub) section, text. I am using black colors and Myriad Pro fonts for the titles, and Palatino for the text.

enter image description here

  1. Next we number the section using

enter image description here

  1. Now we would like to add a numbered equation in the TraditionalForm. Here I totally build upon the answer of @jmlopez, but add numbering of the equations using the format (section.equation). Paste the following in the style editor

Cell[StyleData["DisplayMathNumbered"],
 CellFrameLabels->{{None, 
    Cell[
     TextData[{"(", 
       CounterBox["Section"], ".", 
       CounterBox["DisplayFormulaNumbered"], ")"}], "DisplayMathEquationNumber"]}, {None, None}},
 DefaultFormatType->TraditionalForm,
 TextAlignment->Center,
 LanguageCategory->"Formula",
 AutoSpacing->True,
 ScriptLevel->0,
 AutoMultiplicationSymbol->False,
 SingleLetterItalics->True,
 SpanMaxSize->Infinity,
 CounterIncrements->"DisplayFormulaNumbered",
 FontFamily->"Palatino",
 FontSize->16,
 ShowInvisibleCharacters->All,
 UnderoverscriptBoxOptions->{LimitsPositioning->False},
 GridBoxOptions->{
 GridBoxAlignment->{
  "Columns" -> {{"\[AlignmentMarker]"}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, 
   "RowsIndexed" -> {}}}]

Now in the notebook create a text cell with the equation and go to the Format/Style/Other... Select DisplayMathNumbered. Return to the notebook and continue typing using the standard and very useful shortcuts such as

  • ctrl -, ctrl ^ and ctrl 7 ^ for sub-, super- and over-scripts,
  • esc dg esc for $\dagger$, esc s esc for $\sigma$,
  • insert space between indices (to avoid upright fonts).

The result is quite acceptable.

enter image description here

  1. Now we insert and customize the appearance of some inline equations. To this end, add a tag to the cell with displayed equation for future reference by Cell/Cell Tags/Add Remove Cell Tags.... Refer to this equation in the text, and insert an Inline Math Cell with ctrl 9. We obtain

enter image description here

Notice that the cell with displayed equation is now tagged, and automatically referenced in the text. Now we configure the appearance of the inline formula. To this end we enter a style name InlineCell and hit enter. Then we show the cell content with Cell/Show Expression... and modify it as follows

Cell[StyleData["InlineCell"],
 MenuSortingValue->10000,
 FontFamily->"Palatino",
 FontSize->16,
 FontWeight->"Regular",
 FontSlant->"Plain",
 ScriptSizeMultipliers->0.85,
 PrivateFontOptions->{"FontPostScriptName"->"Automatic"}]
  1. Finally, we may want to save the style for future references by pressing the bottom Install Stylesheet...

Notice, that my solution still has a deficiency that equation is referenced by its number without the section number.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.