MATLAB & LaTeX Syntax Solutions

In summary, the conversation is about difficulties in publishing a file on MATLAB that contains a matrix created using LaTeX. The user is wondering why MATLAB won't accept the matrix, and another user explains that MATLAB only supports standard LaTeX math mode directives and not those that require additional packages. They also provide a solution for adding packages to the source file.
  • #1
gfd43tg
Gold Member
950
50
Hello,

I am trying to publish a file on matlab, and for some reason it won't accept my code, even though it works on this forum. Does MATLAB use some other syntax for matrices?

$$ \vec {x} = \begin {bmatrix} T-T_{s} \\ C_{A} - C_{As} \\ C_{P} - C_{Ps} \end {bmatrix}$$
upload_2015-9-9_18-8-31.png
 

Attachments

  • upload_2015-9-9_16-38-44.png
    upload_2015-9-9_16-38-44.png
    36.1 KB · Views: 825
Last edited:
Physics news on Phys.org
  • #2
I've never mixed Matlab with LaTeX, but bmatrix is not part of LaTeX, it is an AMS extension.

You have to do matrices in regular LaTeX "manually," something like
Code:
\left[ \begin{array}{c} a \\ b \\ c \end{array} \right]
 
  • Like
Likes gfd43tg
  • #3
Thank you, that fixed it.
 
  • #4
I still don't understand why MATLAB won't accept this, but the latex on PF will (what is going on with the dCA/dt term !?)

upload_2015-9-10_13-56-52.png


$$ \vec {\dot {x}} = \left[ \begin{array}{c} \frac {dT}{dt} \\ \frac
% {dC_{A}}{dt} \\ \frac {dC_{P}}{dt} \end{array} \right] = \left[ \begin{array}{c} -\frac{F}{V} & F \frac {\Delta H_{rxn}}{\rho V c_{p}} & \frac {\beta}{\rho V c_{p}} \frac {1}{2 \sqrt{C_{P}}} \\ 0 & -\frac {F}{V}-2kC_{A} & 0 \\ 0 & 2kC_{A} & - \frac {F}{V} \end{array} \right] $$
 

Attachments

  • upload_2015-9-10_13-55-48.png
    upload_2015-9-10_13-55-48.png
    7.3 KB · Views: 518
  • upload_2015-9-10_13-57-2.png
    upload_2015-9-10_13-57-2.png
    7.5 KB · Views: 510
Last edited:
  • #5
According to the doc, http://www.mathworks.com/help/matla...matlab-comments-for-publishing.html#btj5jsh-1

"MATLAB publishing supports standard LaTeX math mode directives. Text mode directives or directives that require additional packages are not supported."

So any markup that requires a package (such as amsmath) is out.

EDIT: It appears that you can add packages by modifying a source file. See this thread for more info:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/283068
 
Last edited:
  • Like
Likes gfd43tg

FAQ: MATLAB & LaTeX Syntax Solutions

1. What is MATLAB?

MATLAB is a programming language and interactive environment commonly used in scientific and engineering fields. It allows for matrix manipulations, plotting of data and functions, implementation of algorithms, and creation of user interfaces.

2. What is LaTeX?

LaTeX is a typesetting language used for creating professional-looking documents, particularly in the fields of mathematics, computer science, and engineering. It allows for precise control over formatting and is often used for academic papers, reports, and presentations.

3. How can I use MATLAB and LaTeX together?

MATLAB and LaTeX can be used together through the integration of the MATLAB publishing feature. This allows for the creation of documents that contain both code and richly formatted text, equations, and graphics. It is commonly used for creating technical reports, publications, and presentations.

4. What are some common syntax errors in MATLAB?

Some common syntax errors in MATLAB include missing or incorrect parentheses, brackets, or quotation marks, misspelled function names or variables, and incorrect use of operators. It is important to carefully proofread code and use the built-in debugging tools to catch and fix these errors.

5. How can I improve my skills in using MATLAB and LaTeX?

The best way to improve skills in using MATLAB and LaTeX is through practice and utilizing available resources such as online tutorials, documentation, and forums. It can also be helpful to work on projects and collaborate with others who have experience in these languages. Additionally, attending workshops or taking courses can provide a structured learning environment and help deepen understanding of the languages.

Similar threads

Replies
3
Views
1K
Replies
1
Views
2K
Replies
12
Views
3K
Replies
2
Views
4K
Replies
1
Views
1K
Replies
3
Views
700
Replies
7
Views
1K
Replies
7
Views
3K
Back
Top