> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/tr/sorular-ve-cevaplar/16-how-can-i-include-matlab-code-in-my-latex-document.md).

# LaTeX belgemde MATLAB kodunu nasıl eklerim?

Bu [`matlab-prettifier` paketini](https://www.ctan.org/pkg/matlab-prettifier) MATLAB kodunu dizmek için kullanılabilir ve bir [tex.stackexchange'deki bir soru](https://tex.stackexchange.com/questions/75116/what-can-i-use-to-typeset-matlab-code-in-my-document).

### lstlisting ortamı

Paketinizi ekledikten sonra `matlab-prettifier` paketi belgenize şu yolla

```latex
\usepackage{matlab-prettifier}
```

şunu kullanabilirsiniz: `lstlisting` ortamını MATLAB kodunu dizmek için:

```latex
\begin{lstlisting}[<options>]
MATLAB kodu...
\end{lstlisting}
```

burada `<options>` anahtar-değer çiftleri kullanılarak değerleri ayarlanan, virgülle ayrılmış bir parametre listesidir (yani, `parametre=değer`).

* **Not**: Bu `matlab-prettifier` paketi şu temel üzerine kuruludur: `listings` paketi, tarafından sağlanan özelliklerin kullanılmasına olanak tanır `listings`, dahil olmak üzere içindeki parametreleri `<options>` olan `lstlisting` ortamı. Ancak, bazı `listings` parametrelerin *yapmaz* kullanılması gerekir ve okuyuculara ... başvurmaları tavsiye edilir [`matlab-prettifier` belgelere](http://mirrors.ctan.org/macros/latex/contrib/matlab-prettifier/matlab-prettifier.pdf) daha fazla ayrıntı için.

Dizilmiş MATLAB kodunun görsel görünümü şu kullanılarak değiştirilebilir: `stil` parametresi; bu parametre üç değeri destekler:

* `Matlab-editor`
* `Matlab-bw`
* `Matlab-Pyglike`

Aşağıdaki örnekler bu stillerin nasıl kullanılacağını gösterir.

### Örnekler

İşte, MATLAB kodunu kullanarak bir örnek `matlab-prettifier`’in belgelerinden, şu stili uygulayan `Matlab-editor` stil:

```latex
\documentclass[a4paper]{article}
\usepackage{matlab-prettifier}
\begin{document}

\begin{lstlisting}[style=Matlab-editor]
%% Örnek Matlab kodu
!mv test.txt test2.txt
A = [1, 2, 3;... foo
     4, 5, 6];
s = 'abcd';
for k = 1:4
  Disp(s(k)) % bar
end
%{
x satır vektörünü oluşturun, ardından ters çevirin
%}
x = linspace(0,1,101);
y = x(end:-1:1);
\end{lstlisting}
\end{document}
```

[Bu örneği Overleaf'te açın](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+matlab-prettifier+example\&snip=%5Cdocumentclass%5Ba4paper%5D%7Barticle%7D%0A%5Cusepackage%7Bmatlab-prettifier%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cbegin%7Blstlisting%7D%5Bstyle%3DMatlab-editor%5D%0A%25%25+Sample+Matlab+code%0A%21mv+test.txt+test2.txt%0AA+%3D+%5B1%2C+2%2C+3%3B...+foo%0A+++++4%2C+5%2C+6%5D%3B%0As+%3D+%27abcd%27%3B%0Afor+k+%3D+1%3A4%0A++Disp%28s%28k%29%29+%25+bar%0Aend%0A%25%7B%0Acreate+row+vector+x%2C+then+reverse+it%0A%25%7D%0Ax+%3D+linspace%280%2C1%2C101%29%3B%0Ay+%3D+x%28end%3A-1%3A1%29%3B%0A%5Cend%7Blstlisting%7D%0A%5Cend%7Bdocument%7D)

Bu örnek aşağıdaki çıktıyı üretir:

![Overleaf’te LaTeX ile dizilmiş MATLAB kodu](/files/82b09c4b376c23b60ac55cb0b0bd4dc294f49106)

Bir sonraki örnek, şu için değerleri ayarlar: `çerçeve` ve `numaralar` tarafından sağlanan parametreler `listings` paketi:

```latex
\documentclass[a4paper]{article}
\usepackage{matlab-prettifier}
\begin{document}

\begin{lstlisting}[
frame=single,
numbers=left,
style=Matlab-Pyglike]
%% Örnek Matlab kodu
!mv test.txt test2.txt
A = [1, 2, 3;... foo
     4, 5, 6];
s = 'abcd';
for k = 1:4
  Disp(s(k)) % bar
end
%{
x satır vektörünü oluşturun, ardından ters çevirin
%}
x = linspace(0,1,101);
y = x(end:-1:1);
\end{lstlisting}
\end{document}
```

[Bu örneği Overleaf'te açın](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+second+matlab-prettifier+example\&snip=%5Cdocumentclass%5Ba4paper%5D%7Barticle%7D%0A%5Cusepackage%7Bmatlab-prettifier%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cbegin%7Blstlisting%7D%5B%0Aframe%3Dsingle%2C%0Anumbers%3Dleft%2C%0Astyle%3DMatlab-Pyglike%5D%0A%25%25+Sample+Matlab+code%0A%21mv+test.txt+test2.txt%0AA+%3D+%5B1%2C+2%2C+3%3B...+foo%0A+++++4%2C+5%2C+6%5D%3B%0As+%3D+%27abcd%27%3B%0Afor+k+%3D+1%3A4%0A++Disp%28s%28k%29%29+%25+bar%0Aend%0A%25%7B%0Acreate+row+vector+x%2C+then+reverse+it%0A%25%7D%0Ax+%3D+linspace%280%2C1%2C101%29%3B%0Ay+%3D+x%28end%3A-1%3A1%29%3B%0A%5Cend%7Blstlisting%7D%0A%5Cend%7Bdocument%7D)

Bu örnek aşağıdaki çıktıyı üretir:

![Overleaf’te LaTeX ile dizilmiş MATLAB kodu](/files/ebb0cb07e77535443355823f19e63d3c4fb87e98)

### Bir dosyada saklanan MATLAB kodunu kullanma

MATLAB kodunu doğrudan LaTeX belgenize eklemek yerine, şu komutu kullanın: `\lstinputlisting` harici bir dosyada bulunan kodu içe aktarmak ve dizmek için:

```latex
\lstinputlisting[<options>]{<filename>}
```

burada

* `<options>` anahtar-değer çiftleri olarak sağlanan, virgülle ayrılmış bir parametre listesidir [(yukarıya bakın)](#matopts);
* `<filename>` MATLAB kodu içeren bir dosyanın yoludur.

Örneğin, şu dosyayı içe aktarmak için `sample.m` ve onu şu stil ile dizmek için `Matlab-bw` şu stili yazarsınız

```latex
\lstinputlisting[style=Matlab-bw]{sample.m}
```

Bir sonraki örnek kodun etrafına bir çerçeve yerleştirir, kod satırlarını numaralandırır (solda) ve şu stili kullanır: `Matlab-bw` stil:

```latex
\lstinputlisting[
frame=single,
numbers=left,
style=Matlab-editor
]{sample.m}
```

Şunu seçin: `Bu örneği Overleaf'te açın` bağlantı ([aşağıya bakın](#openol)) ile, şu içeren bir Overleaf projesini otomatik olarak oluşturmak için `sample.m` MATLAB kod dosyası.

**`main.tex`**

```latex
\documentclass[a4paper]{article}
\usepackage{matlab-prettifier}
\begin{document}
\title{Dosyada bulunan MATLAB kodunu içe aktarma ve dizme}
\lstinputlisting[
frame=single,
numbers=left,
style=Matlab-bw
]{sample.m}

\end{document}
```

**`sample.m`**

```latex
%% Örnek Matlab kodu
!mv test.txt test2.txt
A = [1, 2, 3;... foo
     4, 5, 6];
s = 'abcd';
for k = 1:4
  Disp(s(k)) % bar
end
%{
x satır vektörünü oluşturun, ardından ters çevirin
%}
x = linspace(0,1,101);
y = x(end:-1:1);
```

[Bu örneği Overleaf’te açın (şunu oluşturur: `sample.m` dosyası varsa bunu eklemeniz gerekmeyebilir).](https://www.overleaf.com/docs?engine=pdflatex\&snip_name\[]=main.tex\&snip\[]=%5Cdocumentclass%5Ba4paper%5D%7Barticle%7D%0A%5Cusepackage%7Bmatlab-prettifier%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctitle%7BImporting+and+typesetting+MATLAB+code+contained+in+a+file%7D%0A%5Clstinputlisting%5B%0Aframe%3Dsingle%2C%0Anumbers%3Dleft%2C%0Astyle%3DMatlab-bw%0A%5D%7Bsample.m%7D%0A%0A%5Cend%7Bdocument%7D\&snip_name\[]=sample.m\&snip\[]=%25%25+Sample+Matlab+code%0A%21mv+test.txt+test2.txt%0AA+%3D+%5B1%2C+2%2C+3%3B...+foo%0A+++++4%2C+5%2C+6%5D%3B%0As+%3D+%27abcd%27%3B%0Afor+k+%3D+1%3A4%0A++Disp%28s%28k%29%29+%25+bar%0Aend%0A%25%7B%0Acreate+row+vector+x%2C+then+reverse+it%0A%25%7D%0Ax+%3D+linspace%280%2C1%2C101%29%3B%0Ay+%3D+x%28end%3A-1%3A1%29%3B\&main_document=main.tex)

Bu örnek aşağıdaki çıktıyı üretir:

![Overleaf’te LaTeX ile dizilmiş MATLAB kodu](/files/5c505688785a85ba86c2c74839c1355fe8bef22f)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/tr/sorular-ve-cevaplar/16-how-can-i-include-matlab-code-in-my-latex-document.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
